参考链接: Python中的numpy.isfortran

http://blog.csdn.net/pipisorry/article/details/48208433

真值测试Truth value testing

all(a[, axis, out, keepdims])Test whether all array elements along a given axis evaluate to True.any(a[, axis, out, keepdims])Test whether any array element along a given axis evaluates to True.

只要数组中有一个值为True,则any()返回True;而只有数组的全部元素都为True,all()才返回True。

也可以直接当成array数组的方法使用。

判断numpy数组是否为空

if a.size: print('array is not empty')

如果通过python列表,把一个列表作为一个布尔值会产生True如果有项目,False如果它是空的。lst = []if lst: print "array has items"if not lst: print "array is empty"

[Python的-如何检查数组不为空?]

判断numpy数组中是否有True

array.any()

皮皮blog

数组内容Array contents

isfinite(x[, out])Test element-wise for finiteness (not infinity or not Not a Number).isinf(x[, out])Test element-wise for positive or negative infinity.isnan(x[, out])Test element-wise for NaN and return result as a boolean array.isneginf(x[, y])Test element-wise for negative infinity, return result as bool array.isposinf(x[, y])Test element-wise for positive infinity, return result as bool array.

numpy.isnan

numpy判断一个元素是否为np.NaN,判断某元素是否是nan

numpy.isnan(element)

Note: 不能使用array[0] == np.NaN,总是返回False!

numpy数组元素替换numpy.nan_to_num(x)

判断某元素是否是nan,inf,neginf,如果是,nan换为0,inf换为一个非常大的数,neginf换为非常小的数

numpy.nan_to_num(x)Replace nan with zero and inf with finite numbers.Returns an array or scalar replacing Not a Number (NaN) with zero, (positive) infinity with a very large number and negative infinity with a very small (or negative) number.

数组类型测试Array type testing

iscomplex(x)Returns a bool array, where True if input element is complex.iscomplexobj(x)Check for a complex type or an array of complex numbers.isfortran(a)Returns True if the array is Fortran contiguous but not C contiguous.isreal(x)Returns a bool array, where True if input element is real.isrealobj(x)Return True if x is a not complex type or an array of complex numbers.isscalar(num)Returns True if the type of num is a scalar type.

逻辑操作Logical operations

logical_and(x1, x2[, out])Compute the truth value of x1 AND x2 element-wise.logical_or(x1, x2[, out])Compute the truth value of x1 OR x2 element-wise.logical_not(x[, out])Compute the truth value of NOT x element-wise.logical_xor(x1, x2[, out])Compute the truth value of x1 XOR x2, element-wise.

两个0-1array相与操作

判断两个0-1array有多少个相同的1, 两种方式

rate = np.count_nonzero(np.logical_and(fs_predict_array, ground_truth_array))rate = np.count_nonzero(fs_predict_array * ground_truth_array)不过fs_predict_array

* ground_truth_array返回的是0-1array,而np.logical_and(fs_predict_array ,ground_truth_array)返回的是True-False array,但是都可以使用sum()得到1或者True的数目。

lz亲测下面的logical_and操作运行速度更快,没有count_nonzero会更快。

皮皮blog

比较Comparison

allclose(a, b[, rtol, atol, equal_nan])Returns True if two arrays are element-wise equal within a tolerance.isclose(a, b[, rtol, atol, equal_nan])Returns a boolean array where two arrays are element-wise equal within a tolerance.array_equal(a1, a2)True if two arrays have the same shape and elements, False otherwise.array_equiv(a1, a2)Returns True if input arrays are shape consistent and all elements equal.

greater(x1, x2[, out])Return the truth value of (x1 > x2) element-wise.greater_equal(x1, x2[, out])Return the truth value of (x1 >= x2) element-wise.less(x1, x2[, out])Return the truth value of (x1 < x2) element-wise.less_equal(x1, x2[, out])Return the truth value of (x1 =< x2) element-wise.equal(x1, x2[, out])Return (x1 == x2) element-wise.not_equal(x1, x2[, out])Return (x1 != x2) element-wise.

allclose

如果两个数组在tolerance误差范围内相等,则返回True。

from: http://blog.csdn.net/pipisorry/article/details/48208433

ref: Logic functions

[转载] numpy教程:逻辑函数Logic functions相关推荐

  1. [转载] numpy教程:矩阵matrix及其运算

    参考链接: Python中的numpy.asmatrix http://blog.csdn.net/pipisorry/article/details/48791403 numpy矩阵简介 NumPy ...

  2. [转载] numpy教程:排序、搜索和计数

    参考链接: Python中的numpy.place http://blog.csdn.net/pipisorry/article/details/51822775 numpy排序.搜索和计数函数和方法 ...

  3. Numpy入门教程:05. 逻辑函数

    背景 什么是 NumPy 呢? NumPy 这个词来源于两个单词 – Numerical和Python.其是一个功能强大的 Python 库,可以帮助程序员轻松地进行数值计算,通常应用于以下场景: 执 ...

  4. [转载] python:numpy数学函数和逻辑函数

    参考链接: Python中的numpy.logical_or numpy数学函数和逻辑函数 算术运算numpy.add()numpy.subtract()numpy.multiply()numpy.d ...

  5. [转载] Numpy 数学函数及逻辑函数

    参考链接: Numpy 数学函数 目录 一.向量化和广播 二.数学函数 算数运算 numpy.add numpy.subtract numpy.multiply numpy.divide numpy. ...

  6. numpy(逻辑函数与数学函数)

    逻辑函数 np.isnan:是否为nan值 逻辑运算 1.numpy.logical_not:计算非x元素的真值 2.numpy.logical_and:计算x1 AND x2元素的真值 3.nump ...

  7. [转载] numpy的属性和函数

    参考链接: Python中的numpy.isscalar NumPy的主要对象是同种元素的多维数组.这是一个所有的元素都是一种类型.通过一个正整数元组索引的元素表格(通常是元素是数字).在NumPy中 ...

  8. 【CS231n】斯坦福大学李飞飞视觉识别课程笔记(一):Python Numpy教程(1)

    最近开了一个新坑--[CS231n]斯坦福大学李飞飞视觉识别课程,准备认真学习并记录自己的学习历程. [CS231n]斯坦福大学李飞飞视觉识别课程笔记 由官方授权的CS231n课程笔记翻译知乎专栏-- ...

  9. 初学--Python numpy教程

    本文转载自:http://blog.chinaunix.net/uid-21633169-id-4408596.html 先决条件 在阅读这个教程之前,你多少需要知道点python.如果你想重新回忆下 ...

最新文章

  1. sqlyog怎么连接mysql_Mysql数据库连接过高,怎么快速杀掉连接
  2. LeetCode Algorithm 剑指 Offer 28. 对称的二叉树
  3. VB.NET版机房收费系统—DataGridView应用
  4. EF Core 数据库 Provider 一览
  5. Java设计模式笔记(8)装饰模式
  6. Git clone的使用方法
  7. c语言,期末复习之求多项式分式数列 1+1/2+2/3+3/5 ...........前n项和
  8. php 延时显示代码,php 延时显示代码
  9. 推荐系统实战-概念理解入门篇
  10. Python线性代数扩展库numpy.linalg中几个常用函数
  11. vb 访问远程计算机,vb 连接远程服务器
  12. [再寄小读者之数学篇](2014-05-25 非线性递归数列的敛散性)
  13. linux服务器忘记ssh密码_【Linux】配置linux服务器之间ssh不用密码访问
  14. python下载手机版-python3手机版下载
  15. sofia-sip-ua >= 1.12.12… configure: error: no usable sofia-sip; please install sofia-sip-ua devel pa
  16. 6款 jQuery Lightbox图片查看触控插件
  17. AndroidN多窗口支持
  18. java关注列表_如何从一个Instagram帐户中获取关注者列表?
  19. vs2015不使用方向键移动光标快捷键
  20. LSTM(long short term memory)长短期记忆网络

热门文章

  1. OpenWHO课程 Introduction to COVID-19: methods for detection, prevention, response and control 小抄
  2. 【NOIP2007】【Vijos1378】矩阵取数游戏
  3. PAT 数字分类(20)
  4. Spring框架零基础学习(一):IOC|DI、AOP
  5. [leetcode]62. 不同路径
  6. 2017蓝桥杯C++A:方格分割(DFS)
  7. 教程:Visual Studio 连接 MySQL 数据库(包含常见错误及解决方法)
  8. 利用k-means算法实现图像自动色彩量化
  9. python机器学习库sklearn——线性回归
  10. 想创业?从学会需求谈判开始