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 50多岁生日简短祝福语
13 安徽疫情祝福语简短英语
14 农民朋友发财祝福语简短
15 对生活祝福语简短精辟
16 搬家词简短祝福语朋友
17 女神结婚快乐祝福语简短
18 文学短句祝福语大全简短