本文介绍了Numpy的文档语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尝试自学一些python,我对文档的where函数感到非常困惑.有人可以从下面的文档中逐步解释示例吗?
Trying to teach myself some python and I am super confused from the docs what the where function does. Can somebody explain the example from the documentation below step by step please?
>>> np.where([[True, False], [True, True]],
... [[1, 2], [3, 4]],
... [[9, 8], [7, 6]])
array([[1, 8],
[3, 4]])
推荐答案
基本语法为np.where(x, a, b)
在x
为true的地方,采用a
的元素,在其为false的地方,采用.相当于这样的东西:
The basic syntax is np.where(x, a, b)
Wherever x
is true, take that element of a
, and wherever it's false, take an element of b
. It's equivalent to something like this:
array([[1,],[3,4]])+ array([[,8],[]])
array([[1, ], [3, 4]]) + array([[, 8], [, ]])
array([[1,0],[3,4]])+ array([[0,8],[0,0]])= array([[1,8],[3,4 ]])
array([[1, 0], [3, 4]]) + array([[0, 8], [0, 0 ]]) = array([[1, 8], [3, 4]])
这篇关于Numpy的文档语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!