What is the numpy.asscalar() function in Python?
Overview
The asscaler() function in Python is used to return a scalar equivalent of a size 1 array.
The asscalar() function has been deprecated since the introduction of version 1.16 of NumPy and the numpy.ndarray.item() function has become the alternate function to it. Preceding versions of the NumPy 1.16 version support the ascalar() function, while succeeding versions of it do not.
Syntax
numpy.asscalar(a)
Syntax for the numpy.asscalar() function in Python
Parameter value
The asscaler() function takes a single parameter value, a, which represents the input array of size 1.
Return value
The asscaler() function returns a scalar representation of the input array arr1.
Example
import numpy as np# creating an input arrray of size 1arr1 = np.array([25])# converting to scalarprint(np.asscalar(arr1))
Explanation
- Line 1: We import the
numpymodule. - Line 4: We create an input array of size
1namedarr1. - Line 7: We obtain and print the scalar equivalent of the input array,
arr1, using theasscalar()function.