用法:
dask.array.where(condition, [x, y, ]/)此文档字符串是从 numpy.where 复制的。
可能存在与 Dask 版本的一些不一致之处。
返回从
x或y中选择的元素,具体取决于condition。注意
当仅提供
condition时,此函数是np.asarray(condition).nonzero()的简写。应该首选直接使用nonzero,因为它对子类表现正确。本文档的其余部分仅涵盖提供所有三个参数的情况。- condition:数组,布尔
如果为真,则产生
x,否则产生y。- x, y:array_like
可供选择的值。
x,y和condition需要可广播到某种形状。
- out:ndarray
一个数组,其中元素来自
x,其中condition为 True,元素来自其他地方的y。
参数:
返回:
注意:
如果所有数组都是一维数组,
where等价于:[xv if c else yv for c, xv, yv in zip(condition, x, y)]例子:
>>> a = np.arange(10) >>> a array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) >>> np.where(a < 5, a, 10*a) array([ 0, 1, 2, 3, 4, 50, 60, 70, 80, 90])这也可以用于多维数组:
>>> np.where([[True, False], [True, True]], ... [[1, 2], [3, 4]], ... [[9, 8], [7, 6]]) array([[1, 8], [3, 4]])x、y 和条件的形状一起广播:
>>> x, y = np.ogrid[:3, :4] >>> np.where(x < y, x, 10 + y) # both x and 10+y are broadcast array([[10, 0, 0, 0], [10, 11, 1, 1], [10, 11, 12, 2]])>>> a = np.array([[0, 1, 2], ... [0, 2, 4], ... [0, 3, 6]]) >>> np.where(a < 4, a, -1) # -1 is broadcast array([[ 0, 1, 2], [ 0, 2, -1], [ 0, 3, -1]])
相关用法
- Python dask.array.stats.ttest_ind用法及代码示例
- Python dask.array.ma.masked_values用法及代码示例
- Python dask.array.divmod用法及代码示例
- Python dask.array.negative用法及代码示例
- Python dask.array.overlap.map_overlap用法及代码示例
- Python dask.array.stats.ttest_rel用法及代码示例
- Python dask.array.ma.average用法及代码示例
- Python dask.array.vstack用法及代码示例
- Python dask.array.isneginf用法及代码示例
- Python dask.array.ma.masked_array用法及代码示例
- Python dask.array.matmul用法及代码示例
- Python dask.array.random.weibull用法及代码示例
- Python dask.array.Array.compute_chunk_sizes用法及代码示例
- Python dask.array.random.geometric用法及代码示例
- Python dask.array.around用法及代码示例
- Python dask.array.gradient用法及代码示例
- Python dask.array.coarsen用法及代码示例
- Python dask.array.fft.ifftshift用法及代码示例
- Python dask.array.Array.visualize用法及代码示例
- Python dask.array.square用法及代码示例
注:本文由纯净天空筛选整理自dask.org大神的英文原创作品 dask.array.where。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
