Skip to content

Inconsistent behavior for item assignment to vector arrays #457

@simonthor

Description

@simonthor

Vector Version

1.3.1

Python Version

3.11.4

OS / Environment

Kubuntu Linux 22.04.
vector is installed using pip in a conda environment.

Describe the bug

When trying to assign certain items in a vector numpy array, the behavior is different depending on how it is done.

> v = vector.array({"E": np.arange(4), "px": np.zeros(4), "py": np.zeros(4), "pz": np.zeros(4)})
> print(v)
[(0., 0., 0., 0) (0., 0., 0., 1) (0., 0., 0., 2) (0., 0., 0., 3)]

Assignment with a slice:

> v[1:2] = vector.array({"E": [8], "px": [0], "py": [0], "pz": [0]})
> print(v) # Changes the item correctly
[(0., 0., 0., 0) (0., 0., 0., 8) (0., 0., 0., 2) (0., 0., 0., 3)]

Assignment with a boolean array:

> v[v.E > 2] = vector.array({"E": np.ones(2), "px": np.ones(2), "py": np.ones(2), "pz": np.ones(2)})
> print(v) # Does nothing and fails silently
[(0., 0., 0., 0) (0., 0., 0., 8) (0., 0., 0., 2) (0., 0., 0., 3)]

Assignment with a single index:

> v[1] = vector.array(dict(px=[0.0], py=[0.0], pz=[0.0], E=[3])) # Crashes
TypeError: 'MomentumObject4D' object does not support item assignment

Any additional but relevant log output

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThe problem described is something that must be fixedduplicateThis issue or pull request already existsfeatureNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions