gpt4 book ai didi

python - 解释 numpy.where

转载 作者:太空宇宙 更新时间:2023-11-03 15:54:38 25 4
gpt4 key购买 nike

<分区>

我正在寻找类似于 list.index(value) 的适用于 numpy 数组的东西。我认为 numpy.where 可能会成功,但我不明白它是如何工作的。有人可以解释一下吗

a) 这是什么意思

和 b) 它是否像 list.index(value) 一样工作,但使用 numpy 数组。

这是文档中的文章:

numpy.where(condition[, x, y])

Return elements, either from x or y, depending on condition.
If only condition is given, return condition.nonzero().

Parameters: condition : array_like, bool

When True, yield x, otherwise yield y.

x, y : array_like, optional

Values from which to choose. x and y need to have the same shape as condition. Returns: out : ndarray or tuple of ndarrays

If both x and y are specified, the output array contains elements of x where condition is True, and elements from y elsewhere. If only condition is given, return the tuple condition.nonzero(), the indices where condition is True. See also nonzero, choose

Notes If x and y are given and input arrays are 1-D, where is equivalent to: [xv if c else yv for (c,xv,yv) in zip(condition,x,y)]

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com