轴
# 轴 2表示0轴,5表示1轴
t = np.arange(0,10).reshape((2,5))
print(t)
[[0 1 2 3 4]
[5 6 7 8 9]]
numpy 读取数据
us_file_path = "D:/test/youtube_video_data/US_video_data_numbers.csv"
t1 = np.loadtxt(us_file_path,delimiter=",",dtype="int")
print(t1)
[[4394029 320053 5931 46245]
[7860119 185853 26679 0]
[5845909 576597 39774 170708]
...
[ 142463 4231 148 279]
[2162240 41032 1384 4737]
[ 515000 34727 195 4722]]
沿对角线旋转,0轴变1轴 unpack=True
t2 = np.loadtxt(us_file_path,delimiter=",",dtype="int",unpack=True)
print(t2)
[[4394029 7860119 5845909 ... 142463 2162240 515000]
[ 320053 185853 576597 ... 4231 41032 34727]
[ 5931 26679 39774 ... 148 1384 195]
[ 46245 0 170708 ... 279 4737 4722]]
数组的转置
t3 = np.arange(24).reshape(4,6)
print(t3)
[[ 0 1 2 3 4 5]
[ 6 7 8 9 10 11]
[12 13 14 15 16 17]
[18 19 20 21 22 23]]
#数组转置方式一
print(t3.transpose())
#数组转置方式二
print(t3.T)
#数组转置方式三 转换0和1轴
print(t3.swapaxes(1,0))
[[ 0 6 12 18]
[ 1 7 13 19]
[ 2 8 14 20]
[ 3 9 15 21]
[ 4 10 16 22]
[ 5 11 17 23]]