numpy 输出参数
例子
numpy点函数具有可选参数out=None。此参数使您可以指定要写入结果的数组。该数组必须与返回的数组具有完全相同的形状和类型,否则将引发异常。
>>> I = np.eye(2)
>>> I
array([[ 1., 0.],
[ 0., 1.]])
>>> result = np.zeros((2,2))
>>> result
array([[ 0., 0.],
[ 0., 0.]])
>>> np.dot(I, I, out=result)
array([[ 1., 0.],
[ 0., 1.]])
>>> result
array([[ 1., 0.],
[ 0., 1.]])让我们尝试将结果的dtype更改为int。
>>> np.dot(I, I, out=result) Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: output array is not acceptable (must have the right type, nr dimensions, and be a C-Array)
而且,如果我们尝试使用不同的基础内存顺序(例如Fortran样式)(因此列是连续的而不是行),也会导致错误。
>>> result = np.zeros((2,2), order='F') >>> np.dot(I, I, out=result) Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: output array is not acceptable (must have the right type, nr dimensions, and be a C-Array)
热门推荐
10 八一幼儿祝福语大全简短
11 公司乔迁食堂祝福语简短
12 婚礼结束聚餐祝福语简短
13 儿媳买车妈妈祝福语简短
14 毕业送礼老师祝福语简短
15 同事辞职正常祝福语简短
16 恭贺新婚文案祝福语简短
17 金店立秋祝福语简短英文
18 婆婆高寿祝福语大全简短