w3resource logo
Python Exercises

Python NumPy: Create a vector of size 10 with values ranging from 0 to 1, both excluded

Python NumPy: Array Object Exercise-66 with Solution

Write a Python program to create a vector of size 10 with values ranging from 0 to 1, both excluded.

Sample Solution:-

Python Code:

import numpy as np
x = np.linspace(0,1,12,endpoint=True)[1:-1]
print(x)

Sample Output:

[ 0.09090909  0.18181818  0.27272727  0.36363636  0.45454545  0.5454545
5                                                                      
  0.63636364  0.72727273  0.81818182  0.90909091]

Python Code Editor:

import numpy as np
x = np.linspace(0,1,12,endpoint=True)[1:-1]
print(x)

Improve this sample solution and post your code through Disqus