一湿镀、hash 返回?cái)?shù)值
二、delattr刪除屬性,setattr,hasattr,getattr
setattr(People, "name", "hs")
print(People.name)
三旬昭、all,any 迭代判斷,any為空則為false
list1 = [1, 3, 5, 7, 9]
print(all(list1) < 10)
print(any(list1))
結(jié)果
四蹄皱、slice
五览闰、numpy的運(yùn)用
1.條件賦值
import numpy
l = numpy.arange(10)
print(l)
l2 = l[l > 5]
l3 = l[l % 3 == 0]
print(l2)
print(l3)
2.切片改變數(shù)值
l[1::2] = 1
print(l)
3.where使用
import numpy
l = numpy.arange(10)
l2 = numpy.where(l % 2 == 0, "草", l)
print(l2)
4.數(shù)組重構(gòu) reshape,repeat
import numpy
l = numpy.arange(10)
l2 = l.reshape(2, 5)
print(l2)
b = numpy.repeat(1, 12).reshape(3, -1)
print(b)
5.水平,垂直拼接
import numpy
a = numpy.arange(12).reshape(3, 4)
b = numpy.repeat(1, 12).reshape(3, -1)
c = numpy.vstack([a, b])
d = numpy.hstack([a, b])
print(c)
print(d)
6.獲取兩表共有元素
import numpy
a = numpy.arange(12).reshape(3, 4)
b = numpy.repeat(1, 12).reshape(3, -1)
print(numpy.intersect1d(a, b))
print(numpy.setdiff1d(a, b))