示例#1
0
文件: ma.py 项目: m-rossi/dask
 def _(a, value):
     a = asanyarray(a)
     value = asanyarray(value)
     ainds = tuple(range(a.ndim))[::-1]
     vinds = tuple(range(value.ndim))[::-1]
     oinds = max(ainds, vinds, key=len)
     return blockwise(f, oinds, a, ainds, value, vinds, dtype=a.dtype)
示例#2
0
文件: ma.py 项目: m-rossi/dask
def masked_array(data, mask=np.ma.nomask, fill_value=None, **kwargs):
    data = asanyarray(data)
    inds = tuple(range(data.ndim))
    arginds = [inds, data, inds]

    if getattr(fill_value, "shape", ()):
        raise ValueError("non-scalar fill_value not supported")
    kwargs["fill_value"] = fill_value

    if mask is not np.ma.nomask:
        mask = asanyarray(mask)
        if mask.size == 1:
            mask = mask.reshape((1, ) * data.ndim)
        elif data.shape != mask.shape:
            raise np.ma.MaskError("Mask and data not compatible: data shape "
                                  "is %s, and mask shape is "
                                  "%s." % (repr(data.shape), repr(mask.shape)))
        arginds.extend([mask, inds])

    if "dtype" in kwargs:
        kwargs["masked_dtype"] = kwargs["dtype"]
    else:
        kwargs["dtype"] = data.dtype

    return blockwise(_masked_array, *arginds, **kwargs)
示例#3
0
文件: ma.py 项目: m-rossi/dask
def masked_where(condition, a):
    cshape = getattr(condition, "shape", ())
    if cshape and cshape != a.shape:
        raise IndexError("Inconsistant shape between the condition and the "
                         "input (got %s and %s)" % (cshape, a.shape))
    condition = asanyarray(condition)
    a = asanyarray(a)
    ainds = tuple(range(a.ndim))
    cinds = tuple(range(condition.ndim))
    return blockwise(np.ma.masked_where,
                     ainds,
                     condition,
                     cinds,
                     a,
                     ainds,
                     dtype=a.dtype)
示例#4
0
文件: ma.py 项目: m-rossi/dask
def set_fill_value(a, fill_value):
    a = asanyarray(a)
    if getattr(fill_value, "shape", ()):
        raise ValueError("da.ma.set_fill_value doesn't support array `value`s")
    fill_value = np.ma.core._check_fill_value(fill_value, a.dtype)
    res = a.map_blocks(_set_fill_value, fill_value)
    a.dask = res.dask
    a._name = res.name
示例#5
0
文件: ma.py 项目: m-rossi/dask
def masked_values(x, value, rtol=1e-05, atol=1e-08, shrink=True):
    x = asanyarray(x)
    if getattr(value, "shape", ()):
        raise ValueError("da.ma.masked_values doesn't support array `value`s")
    return map_blocks(np.ma.masked_values,
                      x,
                      value,
                      rtol=rtol,
                      atol=atol,
                      shrink=shrink)
示例#6
0
文件: ma.py 项目: m-rossi/dask
def masked_equal(a, value):
    a = asanyarray(a)
    if getattr(value, "shape", ()):
        raise ValueError("da.ma.masked_equal doesn't support array `value`s")
    inds = tuple(range(a.ndim))
    return blockwise(np.ma.masked_equal,
                     inds,
                     a,
                     inds,
                     value, (),
                     dtype=a.dtype)
示例#7
0
文件: ma.py 项目: m-rossi/dask
def masked_outside(x, v1, v2):
    x = asanyarray(x)
    return x.map_blocks(np.ma.masked_outside, v1, v2)
示例#8
0
文件: ma.py 项目: m-rossi/dask
def masked_invalid(a):
    return asanyarray(a).map_blocks(np.ma.masked_invalid)
示例#9
0
文件: ma.py 项目: m-rossi/dask
def filled(a, fill_value=None):
    a = asanyarray(a)
    return a.map_blocks(np.ma.filled, fill_value=fill_value)
示例#10
0
文件: ma.py 项目: m-rossi/dask
def getmaskarray(a):
    a = asanyarray(a)
    return a.map_blocks(np.ma.getmaskarray)
示例#11
0
文件: ma.py 项目: m-rossi/dask
def getdata(a):
    a = asanyarray(a)
    return a.map_blocks(np.ma.getdata)