October 2019
Beginner to intermediate
674 pages
16h 43m
English
NumPy arrays can be created in several ways via calls to various NumPy methods. The arrays can be created using the data in lists or any other data structures, by specifying numerical ranges to obtain uniformly spaced values or by generating random samples.
The simplest routine to create an array is through the array function. This function accepts any sequential object, such as a list or tuple, and converts it to an array. The following code snippet shows how a 1D array can be created through the array function:
In [12]: array1d = np.array([1, 2, 3, 4])In [13]: array1dOut [13]: array([1, 2, 3, 4])
Similarly, a multidimensional array can be created by passing a list of lists to the array function:
In [14]: array2d = np.array([[0, ...
Read now
Unlock full access