np.newaxis

xiaoxiao2021-03-01  11

在原有得到矩阵中增加一个轴,

实际上上np.newaxis的值为无

print(np.newaxis) #None

np.newaxis的位置决定要在哪个维度增加

import numpy as np a = np.arange(1, 10) a = np.reshape(a, (3, 3)) print(a[:, np.newaxis].shape) ''' shape(3, 1, 3) array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) ''' a = np.mean(a, axis=1) ''' a = [2. 5. 8.] a.shape = (3,) ''' a = a[:, np.newaxis, np.newaxis] ''' array([[[[[2.]]]], [[[[5.]]]], [[[[8.]]]]]) shape(3, 1, 1) ''' a[:, np.newaxis, np.newaxis]

 

转载请注明原文地址: https://www.6miu.com/read-4150129.html

最新回复(0)