w3resource logo
Python Exercises

Python NumPy: Create a 1-D array going from 0 to 50

Python NumPy: Array Object Exercise-44 with Solution

Write a Python program to create a 1-D array going from 0 to 50 and an array from 10 to 50.

Sample Solution:-

Python Code:

import numpy as np
x = np.arange(50)
print("Array from 0 to 50:")
print(x)
x = np.arange(10, 50)
print("Array from 10 to 50:")
print(x)

Sample Output:

Array from 0 to 50:                                                    
[ 0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 2
3 24                                                                   
 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 4
8 49]                                                                  
Array from 10 to 50:                                                   
[10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 3
3 34                                                                   
 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49]

Python Code Editor:

import numpy as np
x = np.arange(50)
print("Array from 0 to 50:")
print(x)
x = np.arange(10, 50)
print("Array from 10 to 50:")
print(x)

Improve this sample solution and post your code through Disqus