Numpy: Numerical ranges: linspace, arange

19 August 2020

Code

# Import library
import numpy as np

# np.linspace(): create array
x = np.linspace(start=1, stop=10, num=10)


# np.arange(): create array
y = np.arange(start=1, stop=10, step=1)


# Output
print("np.linspace(): \n", x)
print(type(x), x.dtype, '\n')

print("np.arange(): \n", y)
print(type(y), y.dtype)

Output

np.linspace(): 
 [ 1.  2.  3.  4.  5.  6.  7.  8.  9. 10.]
<class 'numpy.ndarray'> float64 

np.arange(): 
 [1 2 3 4 5 6 7 8 9]
<class 'numpy.ndarray'> int64






Any errors in code above?
Please send a message.