Convert an NumPy array to a Python list
You can convert a NumPy array to a Python list. python import numpy a = numpy.array([1, 2, 3, 4, 5, 6]) b = numpy.array([[1, 2, 3], [...
NumPy array - Basic usage
The NumPy `where()` returns all the indices of the array elements that fulfill the given conditions. python import numpy as np a = np.ar...
Get the index of the max value in an array in NumPy
Getting the position of the max value in a NumPy array: python import numpy as np a = np.array([5, 6, 7, 4]) b = np.array([3, 2, 1]) ...
NumPy count_nonzero() - Count the number of non-zero elements in an array
The `count_nonzero()` counts the number of non-zero elements in a NumPy array. python import numpy a1 = numpy.array([5, 0, 9, 1]) a2 = ...
Concatenate NumPy arrays
NumPy arrays can be concatenated by `concatenate()`. python import numpy a = numpy.array([7, 8, 9]) b = numpy.array([4, 5, 6]) c = n...
Iterate a NumPy array in the for loop
A NumPy array can be iterated in the for statement like Python list. python import numpy a = numpy.array([4, 5, 6, 7]) for n in a: ...
NumPy array_split() - Split an array to subarrays
A NumPy array can be split by `array_split()`. python import numpy a = numpy.array([1, 2, 3, 4, 5, 6]) b = numpy.array_split(a, 2) c...
Add a NumPy array and Python integer - Arithmetic operations of NumPy array and Python numbers
A NumPy array can be added to Python numbers. python import numpy a = numpy.array([1, 2, 3]) b = a + 1 print(b) # [2 3 4] ## ...
NumPy reshape() - Convert 1D array to 2D array
You can create a 2D array from 1D array in Python NumPy. python import numpy a = numpy.array([1, 2, 3, 4, 5, 6]) b = a.reshape(2, 3) ...
NumPy delete - Delete the items from an array
The item of a NumPy array can be deleted or removed by `delete` method. python import numpy a = numpy.array([3, 4, 5, 6]) b = numpy.d...
NumPy array and index - How to get the value of a given index
You can get the value of a NumPy array by an index. python import numpy a = numpy.array([2, 1, 3]) print(a[0]) # 2 print(a[1]) # 1...
NumPy sort: Sort an array by ascending or descending
NumPy has `sort` function sorting an array ascending. python import numpy a = numpy.array([2, 1, 5, 4, 3]) b = numpy.sort(a) c = num...
How to select the subarray of a NumPy array satisfying a condition
The following code shows to get the subarray of an array satisfying the condition. python import numpy a = numpy.array([3, 5, 7, 9, 11])...
NumPy where - How to get the subarray of a NumPy array satisfying a condition
To get the subarray of an array satisfying the condition, `numpy.where` can be used like sql where. python import numpy a = numpy.array(...
NumPy random.randint - How to get random integers | Python
NumPy has `random` module and it has `randint` function that returns random integers as an array. python import numpy a1 = numpy.random....
How to make an arithmetic progression in NumPy (Python)
The NumPy `arange()` is almost the same as the Python range. The `arange()` returns an arithmetic progression. python import numpy a1 = ...
NumPy flatten() - Convert the 2D or 3D array to 1D array | Python
NumPy `flatten()` converts the multi-dimensional array to the "flattened" 1D array. python import numpy a1 = numpy.array([1, 2]) a2 = n...
Sum all the elements in a NumPy array by column or row
NumPy sum calculates the sum of elements in a vector or matrix (array). python import numpy a1 = numpy.array([1, 2]) a2 = numpy.array([...
NumPy zeros - How to create zero vector or matrix and how to use dtype option
You can create a zero vector or matrix to use numpy.zeros. python import numpy a = numpy.zeros(2) print(a) # [0. 0.] print(type(a))...
NumPy shape: The dimension of array (or matrix)
`shape` is a method of NumPy array and returns the shape of it. python import numpy a = numpy.array([[1, 2, 3], [4, -7, 10]]) s = a.s...
Add, subtract, multiply NumPy array
In Python, a vector can be expressed by NumPy array. python import numpy as np v = np.array([1, 3.1]) v1 = -v v2 = v * 2 v3 = v * (-3...
NumPy Array
NumPy Vector
NumPy Matrix
NumPy Statistics
NumPy function
© Rollpie