Python 3.7.4 lacks a proper linspace function?

  • Context: Python 
  • Thread starter Thread starter Wrichik Basu
  • Start date Start date
  • Tags Tags
    Function Python
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
2 replies · 2K views
Messages
2,188
Reaction score
2,694
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?
 
Physics news on Phys.org
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   Reactions: Wrichik Basu