import numpy as np
arr = np.arange(10)
print(arr.reshape(2, 5))
print(arr.reshape(5, -1))
print(arr.reshape(-1, 5))
#修改向量本身
arr.resize(2, 5)
print(arr)
arr1 = np.arange(12).reshape(3, 4)
print(arr1)
print(arr1.T)
arr2 = np.arange(6).reshape(2, -1)
print(arr2)
print("按照列优先,展平")
print(arr2.ravel('F'))
print("按照行优先,展平")
print(arr2.ravel())
a = np.floor(10*np.random.random((3, 4)))
print(a)
print(a.flatten())
arr3 = np.arange(3).reshape(3, 1)
print(arr3.shape)
print(arr3.squeeze().shape)
arr4 = np.arange(6).reshape(3, 1, 2, 1)
print(arr4.shape)
print(arr4.squeeze().shape)
arr5 = np.arange(24).reshape(2, 3, 4)
print(arr5.shape)
print(arr5.transpose(1, 2, 0).shape)
a0 = np.array([1, 2, 3])
b0 = np.array([4, 5, 6])
c0 = np.append(a0, b0)
print(c0)
a1 = np.arange(4).reshape(2, 2)
b1 = np.arange(4).reshape(2, 2)
c1 = np.append(a1, b1, axis=0)
print('按行合并后的结果')
print(c1)
print('合并后数据维度', c1.shape)
d1 = np.append(a1, b1, axis=1)
print('按列合并后的结果')
print(d1)
print('合并后数据维度', d1.shape)
a2 = np.array([[1, 2], [3, 4]])
b2 = np.array([[5, 6]])
c2 = np.concatenate((a2, b2), axis=0)
print(c2)
d2 = np.concatenate((a2, b2.T), axis=1)
print(d2)
a3 = np.array([[1, 2], [3, 4]])
b3 = np.array([[5, 6], [7, 8]])
print(np.stack((a3, b3), axis=0))
|