軸axis操作 舉例

import numpy as np
a = np.random.randn(2,3,4) #(2,3,4)
b = np.expand_dims(a, 0) #(1,2,3,4)
c = np.append(1 - b, b, axis=0) #(2,2,3,4)
d = np.append(1 - b, b, axis=1) #(1,4,3,4)
e = np.append(1 - b, b, axis=2) #(1,2,6,4)
f = np.append(1 - b, b, axis=3) #(1,2,3,8)
print(b.shape)
print('1-b',1-b)
print('b',b)
print(c.shape)
print('c',c)
print(d.shape)
print('d',d)
print(e.shape)
print('e',e)
print(f.shape)
print('f',f)

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章