As Scalar Simple
import numpy as np
a = np.arange(12).reshape(2, 3, 2)
a
array([[[ 0, 1],
[ 2, 3],
[ 4, 5]],
[[ 6, 7],
[ 8, 9],
[10, 11]]])
a.shape
(2, 3, 2)
b = np.asscalar(a)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-8-dfb51e49d46b> in <module>()
----> 1 b = np.asscalar(a)
~/anaconda3/envs/py36/lib/python3.6/site-packages/numpy/lib/type_check.py in asscalar(a)
545 warnings.warn('np.asscalar(a) is deprecated since NumPy v1.16, use '
546 'a.item() instead', DeprecationWarning, stacklevel=1)
--> 547 return a.item()
548
549 #-----------------------------------------------------------------------------
ValueError: can only convert an array of size 1 to a Python scalar
b = a.reshape(12)
c = np.asscalar(b)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-10-90c9546333c0> in <module>()
----> 1 c = np.asscalar(b)
~/anaconda3/envs/py36/lib/python3.6/site-packages/numpy/lib/type_check.py in asscalar(a)
545 warnings.warn('np.asscalar(a) is deprecated since NumPy v1.16, use '
546 'a.item() instead', DeprecationWarning, stacklevel=1)
--> 547 return a.item()
548
549 #-----------------------------------------------------------------------------
ValueError: can only convert an array of size 1 to a Python scalar
b.size
12
c = np.array([24])
c
array([24])
c.shape
(1,)
d = np.asscalar(c)
d
24
Headsup:
Asscalar is Deprecated since version 1.16: Deprecated, use numpy.ndarray.item() instead.