Skip to content

argmin / argmax behavior doesn't match documentation #1388

Closed
@lamorton

Description

@lamorton

The documentation reads

Returns:
reduced : DataArray
New DataArray object with argmin applied to its data and the indicated dimension(s) removed.

However, what happens is that the numpy argmin output (single index into the flattened array at which the maximum/minimum is found) is wrapped in a dummy DataArray (similar behavior for Datasets also):

[In1]: x = np.linspace(0,1,5)

[In2]: y = np.linspace(0,1,6)

[In3]: z = np.random.randn(5,6)

[In4]: example = xr.DataArray(z, {'x':x,'y':y},('x','y'))

[In5]: print(example.argmin())

[Out5]: <xarray.DataArray ()>

        array(10)

[In6]: example_ds = xr.Dataset(data_vars={'ex':example})

[In7]: print(example_ds.argmin())

[Out7]: <xarray.Dataset>

        Dimensions:  ()

        Data variables:

        ex       int64 10

I realize that maybe for compatibility reasons it is necessary to make Datasets/DataArrays do this, but it seems like the documented behavior would be nicer. At any rate, the documentation should match the behavior.

Specs:
python 2.7
xarray 0.9.1
numpy 1.11.3

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