Skip to content

Possible conversion bug with record array #3351

Closed

Description

@rougier

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.

Activity

  1. njsmith commented on May 22, 2013

    @njsmith
    Member

    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
    [email protected]:

    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
    .

  2. seberg commented on May 23, 2013

    @seberg
    Member

    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...

  3. added 3 commits that reference this issue on Jun 17, 2016
    2ef0103
  4. added a commit that references this issue on Oct 23, 2017
    ae582a8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions