×

numpy.asscalar() in Python

The numpy.asscalar() function converts an array of size 1 to its scalar equivalent.

Syntax

numpy.asscalar(a)

Parameter

a: This parameter represents an input array of size 1.

Return

This function returns a scalar representation of parameter ‘a’. The output data type is the same type returned by the input’s item method.

Example 1

# Python program explaining 
# numpy.asscalar() function   
import numpy as np 
inp_arr = np.array([ 18 ]) 
print ("Input array: ", inp_arr) 
out_scalar = np.asscalar(inp_arr) 
print ("Output scalar: ", out_scalar)

Output

Input array:  [18]
Output scalar:  18

Example 2

# Python program explaining 
# numpy.asscalar() function   
import numpy as np 
inp_list = [21] 
# changing the list to size 1 array 
inp_arr = np.array(inp_list)  
print ("Input  array from Input list : ", inp_arr) 
# changing the array to scalar   
out_scalar = np.asscalar(inp_arr) 
print ("Output scalar: ", out_scalar)

Output

Input  array from Input list :  [21]
Output scalar:  21

Related Topics

numpy.ndarray.T in Python

numpy.ndarray.T in Python The numpy.ndarray.T attribute makes a Transpose of an array having a dimension greater than or equal to 2. Syntax ndarray.T() Parameter NA Return This attribute returns the transpose of an array Example 1 # Python Program explaining # numpy.ndarray.T()...

1 minute read.

numpy.transpose() in Python

numpy.transpose() in Python The numpy.transpose() permutes the dimensions of an array. Syntax numpy.transpose(a, axes=None) Parameter a : This parameter represents an input array. axes : It is an optional parameter which by default, reverses the dimensions, otherwise permutes the axes according...

1 minute read.

numpy.full() in Python

numpy.full() in Python The full() method of Python numpy class returns a new array of specified shape and type, filled with fill_value. Syntax numpy.full(shape, fill_value, dtype=None, order='C') Parameter shape:This parameter represents the number of rows order :The order parameter can...

1 minute read.

numpy.empty_like() in Python

numpy.empty_like() in Python The empty_like() method of Python numpy class returns a new array with the same shape and type as the specified array. Syntax numpy.empty_like(prototype, dtype=None, order='K', subok=True) Parameters The numpy. empty_like() method consists of four parameters,...

1 minute read.

numpy.asanyarray() in Python with Example

numpy.asanyarray() in Python The asanyarray() function of Python numpy class converts the input to an ndarray, but pass ndarray subclasses through. Syntax numpy.asanyarray(a, dtype=None, order=None) Parameter arr : This parameter includes the input data, in any form that...

1 minute read.

numpy.meshgrid() in Python

numpy.meshgrid() in Python The meshgrid() function of Python numpy class returns the coordinate matrices from coordinate vectors. Syntax numpy.meshgrid(*xi, **kwargs) Parameter The numpy.meshgrid() function consists of four parameters which are as follow: x1, x2,…, xn: This parameter signifies...

2 minutes read.

numpy.atleast_1d() in Python

numpy.atleast_1d() in Python The numpy.atleast_1d() function converts the inputs to arrays with at least one dimension. Syntax numpy.atleast_1d(*arys) Parameter arys1, arys2, … : This parameter represents one or more input arrays. Return This function returns an array, or list...

1 minute read.

numpy.hstack() in Python

numpy.hstack() in Python The numpy.hstack() function stacks the arrays in a sequence horizontally (column wise). Syntax numpy.hstack(tup) Parameter tup: This parameter represents the sequence of ‘ndarrays’ where the arrays must have the same shape, except 1-D...

1 minute read.

numpy.diagflat() in Python

numpy.diagflat() in Python The diagflat() function of Python numpy class creates a two-dimensional array with the array_like input as a diagonal to the new output array. Syntax numpy.diagflat (a, k = 0) Parameter a :...

1 minute read.

numpy.eye() in Python

numpy.eye() in Python: The eye() method of Python numpy class returns a 2-D array with ones on the diagonal and zeros elsewhere. Syntax numpy.eye(N, M=None, k=0, dtype=<class 'float'>, order='C') Parameters The numpy.eye()  method consists of five parameters, which...

1 minute read.

numpy.tri() in Python

numpy.tri() in Python The tri() function of Python numpy class returns an array with ones at and below the given diagonal(k value) and zeros elsewhere. Syntax numpy.tri(N, M=None, k=0, dtype=<class 'float'>) Parameter R : It represents the number...

1 minute read.

numpy.ravel() in Python

numpy.ravel() in Python The numpy.ravel() returns a contiguous flattened array(1-D array), containing the elements of the input. Syntax numpy.ravel(a, order='C') Parameter The numpy.ravel() method consists of two parameters, which are as follows: a: This parameter represents an Input...

2 minutes read.

Numpy Attributes

Numpy Attributes The Numpy collections give attributes to the numpy arrays. These attributes assist us with knowing the shape, aspect, and different properties of a given numpy array. As we know,...

4 minutes read.

numpy.full_like() in Python

numpy.full_like() in Python The full_like() method of Python numpy class returns a full array with the same shape and type as a given array. Syntax numpy.full_like(a, fill_value, dtype=None, order='K', subok=True) Parameter shape :This parameter represents the number of rowsorder...

1 minute read.

numpy.arrange() in Python

Python numpy.arrange() The arrange() function of Python numpy class returns an array with equally spaced elements as per the interval where the interval mentioned is half opened, i.e. [Start, Stop). Syntax numpy.arange([start, ]stop, [step, ]dtype=None) Parameter start :It...

1 minute read.

numpy.concatenate() in Python

numpy.concatenate() in Python The numpy.concatenate() function joins a sequence of arrays along an existing axis. Syntax numpy.concatenate((a1, a2, ...), axis=0, out=None) Parameter a1, a2, … : This parameter represents the sequence of the array where they must have the same shape,...

1 minute read.

numpy.append() in Python

numpy.append() in Python The numpy.append() function appends the values to the end of an array. Syntax numpy.append(arr, values, axis=None) Parameter The numpy.append() function consists of three parameters, which are as follows: arr : This parameter represents the values that are...

1 minute read.

numpy.resize() in Python

numpy.resize() in Python The numpy.resize() returns a new array with the specified shape. If the new array is larger than the original array, then the new array is filled with repeated...

1 minute read.

numpy.fromiter() in Python

numpy.fromiter() in Python The fromiter() function of Python numpy class creates a ndarray by using an iterable object. It returns a one-dimensional ndarray object. Syntax numpy.fromiter(iterable, dtype, count=-1) Parameter The numpy.frombuffer() method consists of three parameters, which...

1 minute read.

numpy.delete() in Python

numpy.delete() in Python The numpy.delete() function returns a new array with sub-arrays along an axis deleted. For 1-D array, this function returns those entries which are not returned by arr[obj]. Syntax numpy.delete(arr, obj, axis=None) Parameter arr: This parameter returns...

2 minutes read.