Skip to content

Asigning a field to a float #1252

Answered by jpivarski
MoAly98 asked this question in Q&A
Jan 26, 2022 · 1 comments · 7 replies
Discussion options

You must be logged in to vote

This has been working for me:

>>> array = ak.Array([{"y": 1}, {"y": 2}, {"y": 3}])
>>> sum = ak.sum(array['y'])
>>> array["x"] = sum
>>> array
<Array [{y: 1, x: 6}, ... x: 6}, {y: 3, x: 6}] type='3 * {"y": int64, "x": int64}'>

Considering that sum is already a defined symbol in Python, and it's a thing that can't be assigned into an ak.Array (<built-in function sum>), maybe your script is seeing the original sum, rather than the output of ak.sum(array['y'])?

I just did a quick check and see that the right-hand-side can be Python numbers (int, float) or NumPy numbers (np.int32, np.float32, etc.). That's not the problem.

Replies: 1 comment 7 replies

Comment options

You must be logged in to vote
7 replies
@jpivarski
Comment options

@MoAly98
Comment options

@agoose77
Comment options

@MoAly98
Comment options

@jpivarski
Comment options

Answer selected by MoAly98
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants