python all_Python numpy.all()用法及代码示例

关于:

numpy.all(array,axis = None,out = None,keepdims = class numpy._globals._NoValue at 0x40ba726c):测试沿着提到的轴的所有数组元素的求值是否为True。

参数:

array :[array_like]Input array or object whose elements, we need to test.

axis :[int or tuple of ints, optional]Axis along which array elements

are evaluated.

The default (axis = None) is to perform a logical AND over all the dimensions of the input

array. Axis may be negative, in which case it counts from the last to the first axis.

out :[ndarray, optional]Output array with same dimensions as Input array,

placed with result

keepdmis:[boolean, optional]If this is set to True, the axes which are

reduced are left in the result as dimensions with size one. With this option, the result

will broadcast correctly against the input array.

If the default value is passed, then keepdims will not be passed through to the all

method of sub-classes of ndarray, however any non-default value will be. If the

sub-classes sum method does not implement keepdims any exceptions will be raised.

返回:

A new Boolean array as per 'out' parameter

代码1:

# Python Program illustrating

# numpy.all() method

import numpy as geek

# Axis = NULL

#  True    False

#  True    True

#  True :False  =  False

print("Bool Value with axis = NONE :", geek.all([[True,False],[True,True]]))

# Axis = 0

#  True    False

#  True    True

#  True :False

print("\nBool Value with axis = 0 :", geek.all([[True,False],[True,True]], axis = 0))

print("\nBool:", geek.all([-1, 4, 5]))

# Not a Number (NaN), positive infinity and negative infinity

# evaluate to True because these are not equal to zero.

print("\nBool:", geek.all([1.0, geek.nan]))

print("\nBool Value:", geek.all([[0, 0],[0, 0]]))

输出:

Bool Value with axis = NONE : False

Bool Value with axis = 0 : [ True False]

Bool: True

Bool: True

Bool Value: False

代码2:

# Python Program illustrating

# numpy.all() method

# Parameter:keepdmis

import numpy as geek

# setting keepdmis = True

print("\nBool Value:", geek.all([[1, 0],[0, 4]], True))

# setting keepdmis = True

print("\nBool Value:", geek.all([[0, 0],[0, 0]], False))

输出:

Bool Value: [False False]

Bool Value: [False False]

VisibleDeprecationWarning:using a boolean instead of an integer

will result in an error in the future

return umr_all(a, axis, dtype, out, keepdims)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值