Skip to content

astype converts numpy array values to 0.0 for structured dtype #7058

Closed
@mpconte

Description

@mpconte

import numpy as np

dtype = np.dtype([('Point', 'f', (3,))])
ones = np.ones(1, dtype=dtype) --> array([([1.0, 1.0, 1.0],)], dtype=[('Point', '<f4', (3,))])
flattened_dtype = np.dtype([('x', 'f'), ('y', 'f'), ('z', 'f')])
flat_ones = ones.astype(flattened_dtype) --> array([(0.0, 0.0, 0.0)], dtype=[('x', '<f4'), ('y', '<f4'), ('z', '<f4')])

numpy version 1.9.2

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions