Numpy的文档语法 [英] Numpy where syntax from docs

查看:45
本文介绍了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:

x =. . [[1,0],[1,1]]),而不是x = [[0,1],[0,0]]

x = . . [[1, 0], [1, 1]]), not x =[[0, 1], [0, 0 ]]

array([[1, 2 ],[3,4]])+ array([[ 7 ,8],[ 9 10 ]])

array([[1, 2], [3, 4]]) + array([[7, 8], [9, 10]])

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的文档语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆