Return evenly spaced values within a given interval in Numpy


Create an array with int elements using the numpy.arange() method. The 1st parameter is the "start" i.e. the start of the interval. The 2nd parameter is the "end" i.e. the end of the interval. The 3rd parameter is the spacing between values. The default step size is 1.

Values are generated within the half-open interval [start, stop). For integer arguments the function is equivalent to the Python built-in range function, but returns an ndarray rather than a list.

The stop is the end of interval. The interval does not include this value, except in some cases where step is not an integer and floating point round-off affects the length of out. The step is the spacing between values. For any output out, this is the distance between two adjacent values, out[i+1] - out[i]. The default step size is 1. If step is specified as a position argument, start must also be given.

Steps

At first, import the required library −

import numpy as np

You need to create an array with int elements using the numpy.arange() method −

arr = np.arange(10, 20)
print("Array...
", arr)

Display the array −

print("
Array type...
", arr.dtype)

Get the array type −

print("
Array type...
", arr.dtype)

Get the dimensions of the Array: −

print("
Array Dimensions...
",arr.ndim)

Get the shape of the array −

print("
Our Array Shape...
",arr.shape)

Get the number of elements of the Array −

print("
Number of elements in the Array...
",arr.size)

Example

import numpy as np

# Creating an array with int elements using the numpy.arange() method
# The 1st parameter is the "start" i.e. the start of the interval
# The 2nd parameter is the "end" i.e. the end of the interval
# The 3rd parameter is the spacing between values. The default step size is 1
arr = np.arange(10, 20)
print("Array...
", arr) # Get the array type print("
Array type...
", arr.dtype) # Get the dimensions of the Array print("
Array Dimensions...
",arr.ndim) # Get the shape of the Array print("
Our Array Shape...
",arr.shape) # Get the number of elements of the Array print("
Number of elements in the Array...
",arr.size)

Output

Array...
[10 11 12 13 14 15 16 17 18 19]

Array type...
int64

Array Dimensions...
1

Our Array Shape...
(10,)

Number of elements in the Array...
10

Updated on: 10-Feb-2022

134 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements