Python 3.7.4 lacks a proper linspace function?

  • Python
  • Thread starter Wrichik Basu
  • Start date
  • #1
1,438
1,300

Main Question or Discussion Point

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?
 

Answers and Replies

  • #2
StoneTemplePython
Science Advisor
Gold Member
2019 Award
1,163
566
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)
 
  • Like
Likes Wrichik Basu
  • #3
1,438
1,300
Another way is to include the endpoint, but increase num to 301. Just found this, btw.
 

Related Threads on Python 3.7.4 lacks a proper linspace function?

  • Last Post
Replies
9
Views
1K
Replies
6
Views
756
Replies
2
Views
5K
Replies
19
Views
1K
Replies
6
Views
3K
Replies
5
Views
896
Replies
4
Views
2K
Replies
2
Views
1K
Replies
5
Views
4K
Top