当前位置: 移动技术网 > IT编程>脚本编程>Python > Python Numpy Tutorials: 数组--4

Python Numpy Tutorials: 数组--4

2019年04月30日  | 移动技术网IT编程  | 我要评论

npcscan怎么清除缓存,haose,手机模拟器安卓版

# -*- coding: utf-8 -*-
"""
python version: 3.5
created on thu may 11 14:42:49 2017
e-mail: eric2014_lv@sjtu.edu.cn
@author: didilv
"""

import numpy as np

a = np.array([[1,2], [3, 4], [5, 6]])

# 寻找元素大于2的值,并且返回其bool值
bool_idx = (a > 2)  # find the elements of a that are bigger than 2;
                    # this returns a numpy array of booleans of the same
                    # shape as a, where each slot of bool_idx tells
                    # whether that element of a is > 2.

print(bool_idx)      # prints "[[false false]
                    #          [ true  true]
                    #          [ true  true]]"

# we use boolean array indexing to construct a rank 1 array
# consisting of the elements of a corresponding to the true values
# of bool_idx
print(a[bool_idx])  # prints "[3 4 5 6]"

# we can do all of the above in a single concise statement:
print(a[a > 2]+10)     # prints "[13 14 15 16]"

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网