w3resource logo

:

Python Exercises

Python NumPy: Create a 1-D array of 30 evenly spaced elements between 2.5. and 6.5, inclusive

Python NumPy: Array Object Exercise-45 with Solution

Write a Python program to Create a 1-D array of 30 evenly spaced elements between 2.5. and 6.5, inclusive.

Sample Solution:-

Python Code:

import numpy as np
x = np.linspace(2.5, 6.5, 30)
print(x)

Sample Output:

[ 2.5         2.63793103  2.77586207  2.9137931   3.05172414  3.1896551
7                                                                      
  3.32758621  3.46551724  3.60344828  3.74137931  3.87931034  4.0172413
8                                                                      
  4.15517241  4.29310345  4.43103448  4.56896552  4.70689655  4.8448275
9                                                                      
  4.98275862  5.12068966  5.25862069  5.39655172  5.53448276  5.6724137
9                                                                      
  5.81034483  5.94827586  6.0862069   6.22413793  6.36206897  6.5      
 ] 

Python Code Editor:

Improve this sample solution and post your code through Disqus