Member-only story
A Comprehensive Guide to NumPy Properties and Methods
4 min readMar 25, 2023
Introduction:
NumPy is a powerful Python library for numerical computation that provides a wide range of functions and tools for performing mathematical operations on arrays and matrices. In this blog, we will discuss some of the most commonly used properties and methods in NumPy and provide examples of their usage.
Properties:
We will start by discussing some of the properties of NumPy. These properties include the number of dimensions, shape, size, data type, item size, and total size of the array. We will provide explanations and examples of each of these properties.
ndarray.ndim
: The number of dimensions (axes) of the array. This is a property of the NumPyndarray
object, which represents an array of values. Thendim
property returns the number of dimensions of the array. For example:
import numpy as np
a = np.array([[1, 2, 3], [4, 5, 6]])
print(a.ndim) # 2
This output indicates that the ndarray
a
has two dimensions.
ndarray.shape
: The dimensions of the array, represented as a tuple. Theshape
property returns a tuple of integers, representing the size of each dimension of the array. For example:
import numpy as np
a = np.array([[1, 2, 3], [4, 5, 6]])…