Python Python 3.7.4 lacks a proper linspace function?

Wrichik Basu

Insights Author
Gold Member
2018 Award
1,103
960
Basically, I wanted to create a Numpy array with linearly spaced integers between 0 and 3, the increment being 0.01.

Yes, I know Numpy offers a linspace function. I used it like this: x = np.linspace(0, 3, num=300) (where np is numpy), and got this:

1566501564585.png


I know that the numbers cannot be exact (can you explain why?). Matlab returns something similar when the linspace function is used.

But then, in Matlab, I can write x = 0:0.01:3, which will give me this:

1566501758159.png


Does Python have something similar?
 

StoneTemplePython

Science Advisor
Gold Member
1,084
517
Have you read the docs on this function?

It seems like the only difference is between


Python:
import numpy as np

np.linspace(0, 3,300, False)
np.linspace(0, 3,300, True)
 

Wrichik Basu

Insights Author
Gold Member
2018 Award
1,103
960
Another way is to include the endpoint, but increase num to 301. Just found this, btw.
 

Want to reply to this thread?

"Python 3.7.4 lacks a proper linspace function?" You must log in or register to reply here.

Related Threads for: Python 3.7.4 lacks a proper linspace function?

Replies
9
Views
1K
Replies
6
Views
614
Replies
2
Views
5K
Replies
19
Views
882
Replies
6
Views
3K
Replies
4
Views
2K
Replies
2
Views
1K

Physics Forums Values

We Value Quality
• Topics based on mainstream science
• Proper English grammar and spelling
We Value Civility
• Positive and compassionate attitudes
• Patience while debating
We Value Productivity
• Disciplined to remain on-topic
• Recognition of own weaknesses
• Solo and co-op problem solving
Top