May 2019
Beginner
528 pages
29h 51m
English
arrays from RangesNumPy provides optimized functions for creating arrays from ranges. We focus on simple evenly spaced integer and floating-point ranges, but NumPy also supports nonlinear ranges.1
arange Let’s use NumPy’s arange function to create integer ranges—similar to using built-in function range. In each case, arange first determines the resulting array’s number of elements, allocates the memory, then stores the specified range of values in the array:
In [1]: import numpy as npIn [2]: np.arange(5)Out[2]: array([0, 1, 2, 3, 4])In [3]: np.arange(5, 10)Out[3]: array([5, 6, 7, 8, 9])In [4]: np.arange(10, 1, -2)
Read now
Unlock full access