issue_comments: 610407293
This data as json
html_url | issue_url | id | node_id | user | created_at | updated_at | author_association | body | reactions | performed_via_github_app | issue |
---|---|---|---|---|---|---|---|---|---|---|---|
https://github.com/pydata/xarray/issues/3945#issuecomment-610407293 | https://api.github.com/repos/pydata/xarray/issues/3945 | 610407293 | MDEyOklzc3VlQ29tbWVudDYxMDQwNzI5Mw== | 1200058 | 2020-04-07T14:06:03Z | 2020-04-07T14:17:12Z | NONE | First prototype: ```python def value_counts(v, global_unique_values, newdim: str): unique_values, counts = dask.compute(*np.unique(v, return_counts=True))
def xr_value_counts(obj, unique_values=None, **kwargs): (newdim, apply_dims), = kwargs.items()
test_da = xr.DataArray( [ [0,1,1,1,3,4], [0,6,1,1,3,4], ], dims=["dim_0", "dim_1"], coords={"dim_1": [2,5,7,4,3,6]}, ) test_values = xr_value_counts(test_da, value_counts="dim_1") assert np.all( test_values.values == np.array([ [1, 3, 1, 1, 0], [1, 2, 1, 1, 1] ]) ) assert np.all( test_values.value_counts == np.array([0, 1, 3, 4, 6]) ) ``` Example: ```python test_da = xr.DataArray( [ [0,1,1,1,3,4], [0,6,1,1,3,4], ], dims=["dim_0", "dim_1"], coords={"dim_1": [2,5,7,4,3,6]}, ) print(test_da) <xarray.DataArray (dim_0: 2, dim_1: 6)>array([[0, 1, 1, 1, 3, 4],[0, 6, 1, 1, 3, 4]])Coordinates:* dim_1 (dim_1) int64 2 5 7 4 3 6Dimensions without coordinates: dim_0print(xr_value_counts(test_da, value_counts="dim_1")) <xarray.DataArray (dim_0: 2, value_counts: 5)>array([[1, 3, 1, 1, 0],[1, 2, 1, 1, 1]])Coordinates:* value_counts (value_counts) int64 0 1 3 4 6Dimensions without coordinates: dim_0``` Probably not the fastest solution and executes eagerly but it works. What do you think? |
{ "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
595784008 |