w3resource

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

NumPy: Array Object Exercise-45 with Solution

Write a NumPy 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:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a NumPy program to create a 1-D array going from 0 to 50 and an array from 10 to 50.
Next: Write a NumPy program to create a 1-D array of 20 element spaced evenly on a log scale between 2. and 5., exclusive.

What is the difficulty level of this exercise?

Test your Python skills with w3resource's quiz



Python: Tips of the Day

Set comprehension:

>>> m = {x ** 2 for x in range(5)}
>>> m
{0, 1, 4, 9, 16}