Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why use np.asscalar nor item() to get scalar value? #97

Open
ciuji opened this issue Nov 20, 2019 · 0 comments
Open

Why use np.asscalar nor item() to get scalar value? #97

ciuji opened this issue Nov 20, 2019 · 0 comments

Comments

@ciuji
Copy link

ciuji commented Nov 20, 2019

in CH_4_Data_manipulation, we use

We can transform the result into a scalar in Python using the asscalar function of numpy. In the following example, the $\ell_2$ norm of x yields a single element tensor. The final result is transformed into a scalar.
In[20]: np.asscalar(x.norm())
Out[20]: 22.494443893432617

Why don't just use x.norm().item() to get the scalar, which seems much easier? Are their any differences?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant