numpy.shape gives inconsistent responses - why?

后端 未结 4 1496
执笔经年
执笔经年 2021-02-04 03:29

Why does the program

import numpy as np

c = np.array([1,2])
print(c.shape)
d = np.array([[1],[2]]).transpose()
print(d.shape)

give

<         


        
4条回答
  •  孤城傲影
    2021-02-04 04:27

    transpose does not change the number of dimensions of the array. If c.ndim == 1, c.transpose() == c. Try:

    c = np.array([1,2])
    print c.shape
    print c.T.shape
    c = np.atleast_2d(c)
    print c.shape
    print c.T.shape
    

提交回复
热议问题