forked from Snailclimb/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharrayboolean.py
More file actions
31 lines (29 loc) · 998 Bytes
/
arrayboolean.py
File metadata and controls
31 lines (29 loc) · 998 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# -*- coding: utf-8 -*-
"""
Created on Mon Mar 12 16:07:17 2018
@author: Administrator
@description: any和all函数
"""
import numpy as np
from numpy.matlib import randn
print('Boolean values are coerced to 1 (True) and 0 (False) in the above methods. Thus, sum is often used as a means of counting True values in a boolean array:')
arr = randn(100)
print("输出生成的随机数数组中数值大于0的个数:")
print((arr > 0).sum())
bools = np.array([False, False, True, False])
print(bools)
print("只要有一个为true就输出true:")
print(bools.any()) # true
print("全部才输出true:")
print(bools.all()) #false
bools2 = np.array([ True, True, True, True])
print(bools2.all()) #true
#两个数组之间
# any():a数组与b数组有一个元素对应相等就输出true
#all():a数组与b数组每个元素都对应相等才输出true
a=np.array([1,2,3])
b=np.array([2,2,3])
boolean=(a==b).all()
boolean2=(a==b).any()
print(boolean)#true
print(boolean2)#true