numpy
  1. numpy-numpyarange

numpy.arange() - ( Creating Arrays with NumPy )

Heading h2

Syntax

numpy.arange([start, ]stop, [step, ]dtype=None)

Example

import numpy as np

# create an array of integers from 0 to 9
arr1 = np.arange(10)
print(arr1)

# create an array of float values from 0 to 1 with 0.1 steps
arr2 = np.arange(0, 1, 0.1)
print(arr2)

# create an array of even numbers from 2 to 10
arr3 = np.arange(2, 11, 2)
print(arr3)

Output

[0 1 2 3 4 5 6 7 8 9]
[0.  0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9]
[ 2  4  6  8 10]

Explanation

numpy.arange() is a function in NumPy that returns an array of evenly spaced values within a specified range. It is similar to Python's built-in range() function, but returns an array instead of a list.

  • start (optional) - The starting value of the array. Defaults to 0.
  • stop - The end value of the array. This value is not included in the array.
  • step (optional) - The step value between each value in the array. Defaults to 1.
  • dtype (optional) - The data type of the array. Defaults to None.

Use

numpy.arange() is commonly used to create arrays of evenly spaced values for use in data analysis, scientific computing, and machine learning. It can be used to create arrays of integers, floats, or other data types.

Important Points

  • numpy.arange() returns an array of evenly spaced values within a specified range.
  • The start and step values are optional and default to 0 and 1, respectively.
  • The end value is not included in the array.
  • The function can be used to create arrays of integers, floats, or other data types.

Summary

In conclusion, numpy.arange() is a useful function for creating arrays of evenly spaced values within a specified range. It is similar to Python's built-in range() function, but returns an array instead of a list. The start and step values are optional and default to 0 and 1, respectively. The end value is not included in the array. The function can be used to create arrays of integers, floats, or other data types and is commonly used in data analysis, scientific computing, and machine learning.

Published on: