Skip to content

numpy.uint64 + int = float64 #15084

@nschloe

Description

@nschloe

When adding int 1 to a numpy {u}int array, usually a type conversion to int64 happens. This is normal. If, however, the type is uint64, the array gets converted to float64. I had not expected that. Perhaps it's correct though. Opinions?

MWE:

import numpy

a = numpy.array(0, dtype=int)
print((a + 1).dtype)  # int64

a = numpy.array(0, dtype=numpy.uint16)
print((a + 1).dtype)  # int64

a = numpy.array(0, dtype=numpy.uint32)
print((a + 1).dtype)  # int64

a = numpy.array(0, dtype=numpy.uint64)
print((a + 1).dtype)  # float64!

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