basic algorithm in python

来源:互联网 发布:警方破特大网络赌球 编辑:程序博客网 时间:2024/05/01 23:00

ASSERT

如何为assert断言语句添加异常参数

assert的异常参数,其实就是在断言表达式后添加字符串信息,用来解释断言并更好的知道是哪里出了问题。格式如下:
assert expression [, arguments]
assert 表达式 [, 参数]

assert len(lists) >=5,’列表元素个数小于5’
assert 2==1,’2不等于1’

np.sum 使用心得与参数详解

a   : input matrix. array_like.axis: axis = 1 , 横着求和, axis = 0 列求和,for example:    Examples

np.sum([0.5, 1.5])
2.0
np.sum([0.5, 0.7, 0.2, 1.5], dtype=np.int32)
1
np.sum([[0, 1], [0, 5]])
6
np.sum([[0, 1], [0, 5]], axis=0)
array([0, 6])
np.sum([[0, 1], [0, 5]], axis=1)
array([1, 5])
If the accumulator is too small, overflow occurs:

np.ones(128, dtype=np.int8).sum(dtype=np.int8)
-128

0 0
原创粉丝点击