Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
214 views
in Technique[技术] by (71.8m points)

python - Size of a linspace output

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

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

1 Reply

0 votes
by (71.8m points)

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...