您的位置:首页 > 编程语言 > Python开发

basic algorithm in python

2017-03-11 14:47 513 查看

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python