8000 ENH: Add a helper function to convert to array or scalar · Issue #8681 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content
ENH: Add a helper function to convert to array or scalar #8681
Closed
@eric-wieser

Description

@eric-wieser

Something so that:

>>> the_func([1, 2])
array([1, 2])
>>> type(_)
np.ndarray
>>> the_func(1)
1
>>> type(_)
np.int32

Can be implemented trivially as

def the_func(x):
    return asanyarray(x)[()]

What should this be called?

  • asanyarray(x, ..., allow_scalar=True)
  • asanyarrayorscalar(x)

Metadata

Metadata

Assignees

No one assigned

    Labels

    01 - Enhancement57 - Close?Issues which may be closable unless discussion continued

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0