E587 Possible conversion bug with record array · Issue #3351 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

Possible conversion bug with record array #3351

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rougier opened this issue May 22, 2013 · 2 comments
Closed

Possible conversion bug with record array #3351

rougier opened this issue May 22, 2013 · 2 comments

Comments

@rougier
Copy link
rougier commented May 22, 2013

I got a weird output from the following script:

import numpy as np

U = np.zeros(1, dtype=[('x', np.float32, (4,4))])

# Problematic
U[0] = np.eye(4)
print U[0]

# Works as expected
U[0] = np.eye(4, dtype=np.float32)
U['x'][0] = np.eye(4)

Output:
([[0.0, 1.875, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 1.875], [0.0, 0.0, 0.0, 0.0]],)

Tested on numpy 1.7.1, confirmed on 1.6.0.

As noted by Chirs Barker on the mailing list, U is a rank-zero array, not a 4X4 array.

@njsmith
Copy link
Member
njsmith commented May 22, 2013

U[0] is a void scalar, and this scalar contains a 4x4 array, so that's the
explanation for that mystery.

The behaviour's still a bug though.

On Wed, May 22, 2013 at 7:28 PM, Nicolas Rougier
notifications@github.comwrote:

I got a weird output from the following script:

import numpy as np

U = np.zeros(1, dtype=[('x', np.float32, (4,4))])

Problematic

U[0] = np.eye(4)
print U[0]

Works as expected

U[0] = np.eye(4, dtype=np.float32)
U['x'][0] = np.eye(4)

Output:
([[0.0, 1.875, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 1.875],
[0.0, 0.0, 0.0, 0.0]],)

Tested on numpy 1.7.1, confirmed on 1.6.0.

As noted by Chirs Barker on the mailing list, U is a rank-zero array, not
a 4X4 array.


Reply to this email directly or view it on GitHubhttps://github.com//issues/3351
.

@seberg
Copy link
Member
seberg commented May 23, 2013

It goes down to direct buffers. To understand the result try: np.eye(4).view('float32'). Directly interpreting buffers is probably wrong though when types are known...

ahaldane added a commit to ahaldane/numpy that referenced this issue Jun 17, 2016
This commit attempts to make structure assignment more consistent, and
then changes multi-field indices to return a view instead of a copy.

Assignment between structures now works "by field position" rather than
"by field name".

Fixes numpy#2353, fixes numpy#6085, fixes numpy#3351, fixes numpy#6085, fixes numpy#6314,
fixes numpy#2346, fixes numpy#7058, fixes numpy#3641, fixes numpy#5994, fixes numpy#7262,
fixes numpy#7493
@charris charris closed this as completed in 7412b85 Sep 9, 2017
theodoregoetz pushed a commit to theodoregoetz/numpy that referenced this issue Oct 23, 2017
This commit attempts to make structure assignment more consistent, and
then changes multi-field indices to return a view instead of a copy.

Assignment between structures now works "by field position" rather than
"by field name".

Fixes numpy#2353, fixes numpy#6085, fixes numpy#3351, fixes numpy#6085, fixes numpy#6314,
fixes numpy#2346, fixes numpy#7058, fixes numpy#3641, fixes numpy#5994, fixes numpy#7262,
fixes numpy#7493
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
0