a=arange(12)
a.reshape(4,3)转换为4*3的二维数组
b=np.random.randint(1,6,(3,4))
b.reval()变为一维向量
a=np.arange(4)
out:array([0, 1, 2, 3])
a.shape
out: (4,)
b=a[:,np.newaxis]在列上添加一个维度,变成4*1
out:array([[0],
[1],
[2],
[3]])
b=a[np.newaxis,:]
out:array([[0, 1, 2, 3]])在行上添加一个维度,变成1*4
排序功能
a=np.random.randint(1,10,(6,4))
out:array([[3, 8, 2, 1],
[1, 9, 9, 3],
[4, 1, 4, 9],
[5, 6, 7, 7],
[5, 1, 9, 4],
[3, 1, 6, 7]])
b=np.sort(a,axis=1)按行进行排序
out:array([[1, 2, 3, 8],
[1, 3, 9, 9],
[1, 4, 4, 9],
[5, 6, 7, 7],
[1, 4, 5, 9],
[1, 3, 6, 7]])
b=np.sort(a,axis=0)按列进行排序
out:array([[1, 1, 2, 1],
[3, 1, 4, 3],
[3, 1, 6, 4],
[4, 6, 7, 7],
[5, 8, 9, 7],
[5, 9, 9, 9]])