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

Categories

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

python numpy arange dtpye? why converting to integer was zero

x = np.arange(0.3, 12.5, 0.6)

print(x)

[ 0.3 0.9 1.5 2.1 2.7 3.3 3.9 4.5 5.1 5.7 6.3 6.9 7.5 8.1 8.7 9.3 9.9 10.5 11.1 11.7 12.3]

x = np.arange(0.3, 12.5, 0.6,int)

print(x)

[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

When dtype = int is specified, it is converting the start, stop and step into the same.

So, it becomes int(start), int(stop), int(step).

Hence, in your case, when dtype = int is specified, the start and step remain 0 and you get an array full of 0s.

This problem has been discussed with explanation here:

https://github.com/numpy/numpy/issues/2457


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...