numpy.asscalar() in Python
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 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) |
chevron_right
filter_none
Output :
Input array : [8] output scalar from input array : 8
Code #2 :
# 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) |
chevron_right
filter_none
Output :
Input array from list : [2] output scalar from input list : 2
Recommended Posts:
- Python | Index of Non-Zero elements in Python list
- Reading Python File-Like Objects from C | Python
- Python | Convert list to Python array
- Python | Merge Python key values to list
- Important differences between Python 2.x and Python 3.x with examples
- Python | Sort Python Dictionaries by Key or Value
- Python | Add Logging to Python Libraries
- Python | Add Logging to a Python Script
- Python | Set 4 (Dictionary, Keywords in Python)
- Python | Visualizing O(n) using Python
- JavaScript vs Python : Can Python Overtop JavaScript by 2020?
- Any & All in Python
- SHA in Python
- abs() in Python
- pow() in Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



