Size of a linspace output

时间:2015-10-06 08:31:32

标签: python numpy

If I execute the code below

x = np.linspace(1, 12, 5)

and if I display I get a result as

array([  1.  ,   3.75,   6.5 ,   9.25,  12.  ])

and if I do a shape() function on x then I get

(5,)

My question is that if we see the result then it is an array with one row and 5 columns then why do I see (5,) in shape. Shouldn't it be (1,5) 1X5 matrix

1 个答案:

答案 0 :(得分:0)

显示不代表它是Matlab的方式是列还是行(如果这是你从中提取你的想法)。

要理解这一点,请尝试以下方法:

import numpy as np
x = np.linspace(1, 12, 5)
x_new = np.expand_dims(x, axis=0)
print(np.shape(x_new))
print(x_new)
相关问题