Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ENH: change default empty array dtype, currently 'float64' #10405

Open
@nschloe

Description

@nschloe

(From #10135.)

In Numpy, empty arrays have the default data type numpy.float64.

print(numpy.array([]).dtype)  # float64

I'm questioning whether this is the right choice.

In principle, the default dtype choice for empty arrays is arbitrary since there is no data to work with. One good reason to choose a small data type is that operations with empty arrays should not needlessly augment the dtype. The current setting leads to rather surprising dtype changes like

print(numpy.concatenate([[0], []]))  # [0.0], not [0]

This would not have happened with, e.g., numpy.array([]).dtype == numpy.int8.

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