Open In App

numpy.asscalar() in Python

Last Updated : 28 Nov, 2018
Comments
Improve
Suggest changes
Like Article
Like
Report
numpy.asscalar() function is used when we want to convert an array of size 1 to its scalar equivalent.
Syntax : numpy.asscalar(arr) Parameters : arr : [ndarray] Input array of size 1. Return : Scalar representation of arr. The output data type is the same type returned by the input’s item method.
Code #1 : Working Python
# Python program explaining
# numpy.asscalar() function

import numpy as geek
# creating a array of size 1
in_arr = geek.array([ 8 ])

print ("Input  array : ", in_arr)
 
  
out_scalar = geek.asscalar(in_arr)
print ("output scalar from input array : ", out_scalar) 
Output :
Input  array :  [8]
output scalar from input array :  8
  Code #2 : Python
# Python program explaining
# numpy.asscalar() function
import numpy as geek

in_list = [2 ]

# changing the list to size 1 array
arr = geek.array(in_list) 

print ("Input  array from list : ", arr)

# changing the array to scalar  
scalar = geek.asscalar(arr)

print ("output scalar from input list : ", scalar) 
Output :
Input  array from list :  [2]
output scalar from input list :  2

Practice Tags :

Similar Reads

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy