The ma.size()
method belongs to the numpy.ma
module in Python. And it is used to obtain the number of elements along a given axis of an array.
The ma.size()
method takes the syntax below:
ma.size(obj, axis=None)
The ma.size()
function takes the following parameter values:
obj
: The input array. It is a required parameter. axis
: The axis along which the counts of the elements are taken. It is an optional parameter. The ma.size()
function returns the size (number of elements) of the specified axis of a given array.
Let's look at the code below:
import numpy as np import numpy.ma as ma # creating an array a = np.array([1, 2, 3, 4, 5, 6]) b = np.array([[1, 2, 3], [4, 5, 6]]) # implementing the ma.size() method c = ma.size(a) d = ma.size(b) print(a) print("The size of array a is: ", c) print(b) print("The size of array b is: ", d)
numpy
module.numpy.ma
module.a
and b
, using the array()
function.ma.size()
function on a
and b
and pass their respective results to c
and d
.a
and b
and their respective shapes, c
and d
.
RELATED TAGS
CONTRIBUTOR
View all Courses