用法:
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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。