Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
212 views
Welcome To Ask or Share your Answers For Others

1 Answer

The display does not represent whether it is columns or rows in the way that Matlab does (if that is what you were drawing your idea from).

To understand this try the following:

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...