numpy函数
时间:2021-03-03 12:17:41
收藏:0
阅读:0
数据创建
randint
创建随机整数array。
np.random.randint(10,size=(2,3))
randint(low, high=None, size=None, dtype=‘l‘)
low为必选参数:
- 若有low与high,则返回两者之间的数据。[
low
,high
)。 - 若只有low,则返回数据在[0,
low
)之间。
返回:返回一个ndarray,或一个整数int(若没有给size参数时)。
np.random.randint(100,size=(1))
np.random.randint(100)
array([3])
21
形状变化
np.flatten()
压成一个向量。
数据处理
np.sort()
np.sort(a, axis = 0)
>>> a = np.array([[3,7],[9,1]])
>>> np.sort(a) #默认是按行排列的,即在vector内部排列元素
array([[3, 7],
[1, 9]])
>>> np.sort(a, axis = 0) # axis=0,按列排
array([[3, 1],
[9, 7]])
>>> np.sort(a, axis = 1)
array([[3, 7],
[1, 9]])
评论(0)