Skip to content

numpy.sign behaves oddly when dtype is numpy.object #6229

@atomicpirate

Description

@atomicpirate

In [1]: import numpy

In [2]: foo = numpy.array([-.1, 0, .1])

In [3]: numpy.sign(foo)
Out[3]: array([-1., 0., 1.])

In [4]: numpy.sign(foo.astype(numpy.object))
Out[4]: array([1, -1, -1], dtype=object)

The underlying data is still just a float:
In [5]: type(foo.astype(numpy.object)[0])
Out[5]: float

This result when using an array of numpy.object does not seem desirable. Either it should operate correctly on the underlying numbers or if called with invalid data (strings, etc) it should throw an exception. This way I could populate an array with heterogeneous data, say a mix of integers and floats, and still get a valid result.

I tested this on:
Mac OS 10.6.8
Python 3.4.2
numpy 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