插入新维度

import numpy as np
a=np.array([1,2,3,4,5])
print ('a:',a)
print('a.shape',a.shape)
a1=a[:,np.newaxis]
print ('a1:\n',a1)
print('a1.shape',a1.shape)
a2=a[np.newaxis,:]
print ('a2:\n',a1)
print('a2.shape',a2.shape)

结果

a: [1 2 3 4 5]
a.shape (5,)
a1:
 [[1]       
 [2]        
 [3]        
 [4]        
 [5]]       
a1.shape (5, 1)
a2:
 [[1]
 [2]
 [3]
 [4]
 [5]]
a2.shape (1, 5)

相关文章:

  • 2022-12-23
  • 2021-07-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-22
  • 2021-12-28
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-01
  • 2021-09-19
  • 2022-12-23
  • 2023-03-20
相关资源
相似解决方案