为什么np.sum([0.5, 0.7, 0.2, 1.5], dtype=np.int32)结果是1?
发布网友
发布时间:2022-05-03 07:16
我来回答
共2个回答
热心网友
时间:2023-10-13 23:09
是先int 再 sum 所以结果是1
相当于[0,0,0,1]
热心网友
时间:2023-10-13 23:09
Sum of array elements over a given axis.
Parameters :
a : array_like
Elements to sum.
axis : integer, optional
Axis over which the sum is taken. By default axis is None,and all elements are summed.
dtype : dtype, optional
The type of the returned array and of the accumulator in whichthe elements are summed. By default, the dtype of a is used.An exception is when a has an integer type with less precisionthan the default platform integer. In that case, the defaultplatform integer is used instead.
out : ndarray, optional
Array into which the output is placed. By default, a new array iscreated. If out is given, it must be of the appropriate shape(the shape of a with axis removed, i.e.,numpy.delete(a.shape, axis)). Its type is preserved. Seedoc.ufuncs (Section “Output arguments”) for more details.
Returns :
sum_along_axis : ndarray
An array with the same shape as a, with the specifiedaxis removed. If a is a 0-d array, or if axis is None, a scalaris returned. If an output array is specified, a reference toout is returned.追问官方的解释我也看了,但是就算是int也应该是2 吧?