import numpy as np
arr1 = np.array([1, 2, 3])
print(arr1)
arr2 = np.zeros(3)
print(arr2)
arr3 = np.ones(3)
print(arr3)
arr4 = np.random.randint(1, 10, 3)
print(arr4)
arr5 = np.arange(3)
print(arr5)
arr6 = np.linspace(1, 3, 3)
print(arr6)
import numpy as np
# 产生随机整数arr
arr1 = np.random.randint(1, 100, 10) # 从 [1, 100)的区间内,取10个整数
# 随机产生小数arr
arr2 = np.random.random(10) # 从[0, 1)之间产生10个小数
# 通过洗牌函数shuffle
arr3 = np.arang(10)
np.random.shuffle(arr3) # 传入np.arr或者list,并对其进行打乱,返回None
结果如下所示:
[51 66 69 10 59 62 42 10 66 38]
[0.36556901 0.00594538 0.96820174 0.15049347 0.17797086 0.0837191
0.64086666 0.27320334 0.4595817 0.19450983]
[5 2 7 9 3 6 8 4 0 1]
import numpy as np
# min,max,sum,mean
a = np.arange(10)
print(np.max(a))
print(np.min(a))
print(np.mean(a))
print(np.sum(a))
# sin,cos,tan,arccos...三角函数
print(np.sin(a))
print(np.cos(a))
print(np.tan(a))
# exp,exp2,sqrt,floor,ceil...
print(np.exp(a))
print(np.exp2(a))
print(np.sqrt(a))
import numpy as np
# logical_or,logical_and,logical_not,logical_xor
a = np.array([0, 0, 0])
b = np.array([1, 1, 0])
print(np.logical_and(a, b))
print(np.logical_or(a, b))
print(np.logical_not(b))
print(np.logical_xor(a, b))
结果:
[False False False]
[ True True False]
[False False True]
[ True True False]
import numpy as np
a = np.arange(5)
res = a <= 2
print(np.sum(res))
print(True == 1)
'''
3
True
'''
手机扫一扫
移动阅读更方便
你可能感兴趣的文章