Skip to content

Support scalar indices and values in put() #513

@svanzwam

Description

@svanzwam

Current Problem
When using the mathematical function put() with a scalar index, a .resize() is required, like this:

modified_array = put(old_array, index.resize(1), new_value.resize(1))

Proposed Solution
It would be nice if scalar values were accepted for the indices and values arguments.

Alternatives Considered
If it's too hard or costs too much performance, documenting this case in the API reference would be helpful.

Additional context
Numpy does accept scalars in the corresponding function:

arr = np.arange(5)
np.put(arr, 0, 5)
print(arr)
# Outputs [5 1 2 3 4]

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions