The title as it is.
It's an in-place change in NumPy.
Python(NumPy)
>>> A = np.ones((3,3))
>>> A
array([[1., 1., 1.],
[1., 1., 1.],
[1., 1., 1.]])
>>> B = np.array([[1, 1, 1], [2, 2, 2]])
>>> B
array([[1, 1, 1],
[2, 2, 2]])
>>> np.add.at(A, [0, 2], B)
>>> A
array([[2., 2., 2.],
[1., 1., 1.],
[3., 3., 3.]])
Note that the . +
operator is added to the + =
operator to make it . + =
, And broadcasting is performed.
+ =
does not broadcast and is not an in-place change.
However, . + =
(Of course) broadcasts, but it is a ** in-place change ** [^ 1].
Julia
julia> A = ones(3,3)
3×3 Array{Float64,2}:
1.0 1.0 1.0
1.0 1.0 1.0
1.0 1.0 1.0
julia> B = [1. 1. 1.; 2. 2. 2.]
2×3 Array{Float64,2}:
1.0 1.0 1.0
2.0 2.0 2.0
julia> selectdim(A, 1, [1, 3]) .+= B
2×3 view(::Array{Float64,2}, [1, 3], :) with eltype Float64:
2.0 2.0 2.0
3.0 3.0 3.0
julia> A
3×3 Array{Float64,2}:
2.0 2.0 2.0
1.0 1.0 1.0
3.0 3.0 3.0
Sources numpy.ufunc.at — NumPy v1.19 Manual Arrays · The Julia Language Multi-dimensional Arrays · The Julia Language Mathematical Operations and Elementary Functions · The Julia Language
Recommended Posts