np.where的输出
时间: 2023-10-17 10:01:56 浏览: 69
np.where的输出取决于条件(condition)。当条件满足时,输出x;当条件不满足时,输出y。如果条件是一个一维数组,那么输出的结果也将是一个一维数组,其中满足条件的元素将被替换为x,不满足条件的元素将被替换为y。举个例子,如果我们有一个一维数组A = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],我们可以使用np.where(A, 1, -1)来替换满足条件的元素为1,不满足条件的元素为-1,输出的结果将是[-1, 1, 1, 1, 1, 1, 1, 1, 1, 1]。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *3* [Python中的np.where()是什么意思(附代码解读)](https://blog.csdn.net/wzk4869/article/details/126023597)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* [numpy.where() 用法详解](https://download.csdn.net/download/weixin_38571759/13996348)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文