Skip to content

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

Open
@ciuji

Description

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?

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions