home / github / issues

Menu
  • Search all tables
  • GraphQL API

issues: 188395497

This data as json

id node_id number title user state locked assignee milestone comments created_at updated_at closed_at author_association active_lock_reason draft pull_request body reactions performed_via_github_app state_reason repo type
188395497 MDU6SXNzdWUxODgzOTU0OTc= 1102 full_like, zeros_like, ones_like 6213168 closed 0     2 2016-11-10T01:12:58Z 2016-11-28T03:42:39Z 2016-11-28T03:42:39Z MEMBER      

I'd like to add the following top-level functions to xarray:

``` def const_like(array, value=0): """Return a new array with the same shape of array and the given constant value. If array is dask-backed, return a new dask-backed array with the same chunks.

:param array:
    a numpy or dask-backed xarray.DataArray
:param value:
    any scalar number
"""
if isinstance(array.data, dask.array.Array):
    if value == 0:
        data = dask.array.zeros(
            array.data.shape,
            chunks=array.data.chunks,
            dtype=array.data.dtype)
    else:
        data = dask.array.ones(
            array.data.shape,
            chunks=array.data.chunks,
            dtype=array.data.dtype)
else:
    if value == 0:
        data = numpy.zeros_like(array.data)
    else:
        data = numpy.ones_like(array.data)
if value not in (0, 1):
    data = data * value

return xarray.DataArray(data, dims=array.dims, coords=array.coords, attrs=array.attrs)

def zeros_like(array): return const_like(array, 0)

def ones_like(array): return const_like(array, 1) ```

The above would need to be expanded to support Dataset and Variable objects. In Datasets, the data_vars would be constants whereas all other variables would be copied verbatim. Thoughts?

{
    "url": "https://api.github.com/repos/pydata/xarray/issues/1102/reactions",
    "total_count": 4,
    "+1": 4,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  completed 13221727 issue

Links from other tables

  • 1 row from issues_id in issues_labels
  • 2 rows from issue in issue_comments
Powered by Datasette · Queries took 0.715ms · About: xarray-datasette