i try to find that how to using multi-dimension arrays minus a constant in julia1.0 documents, but i fail. so can you help me? thanks
Do you need to subtract a scalar from each element? Then use broadcasting, eg
some_array .- some_scalar
If you need something else, please explain in detail (eg provide an example of the desired input and output).
xtrn[:,:,1,:] = xtrn[:,:,1,:].-rxtrn;
where xtrn is a 4 dim arrays and rxtrn is a constant.
when i run the file in this line, the peoplem as following occured.
ERROR: LoadError: syntax: extra token “rxtrn” after end of expression
there occur a strange thing. when i change xtrn[:,:,1,:] = xtrn[:,:,1,:].-rxtrn to xtrn[:,:,1,:] = xtrn[:,:,1,:].-rxtrn;xtr=xtrn[:,:,1,:].-rxtrn;xtrn[:,:,1,:]=xtr. it work. And the last sentence have no need to change, do you know the reason. I want to know that.
xtrn[:,:,1,:] = xtrn[:,:,1,:].-rxtrn;
xtr=xtrn[:,:,1,:].-rxtrn
xtrn[:,:,1,:]=xtr;
xtrn[:,:,2,:] = xtrn[:,:,2,:].-gxtrn;
xtrn[:,:,3,:] = xtrn[:,:,3,:].-bxtrn;
Please post an MWE.
Welcome to the Julia Discourse! We are enthusiastic about helping Julia programmers, both beginner and experienced. This public service announcement (PSA) outlines best practices when asking for help. Following these points makes it easier for us to help you and more likely you’ll get a prompt, useful answer. Keywords are highlighted to make it easier to refer to specific points. Choose a descriptive title that captures the key part of your question, eg “plots with multiple axes” instead of …
It may need a .=
with an indexing operation ( a[]
) on the left, and with all(?) broadcast-like ( .-
) operators on the right, for the broadcast fusion optimization
a = ones(3,3,3,3);
a[:,:,1,:] .= a[:,:,1,:] .- 1;
b = ones(3,2); c = ones(2, 1);
b[:, 1] = b[:,1] * c[1,1] ##matrix multiply
thank you. I solved it.