Forums Register Login

release 1 dimensional array from 2 dimensional array

+Pie Number of slices to send: Send
I have a 2x2 matrix and a 2 dimensional array.
Let's say, my matrix is [a b] and array is [[1, 2], [3, 4], [5, 6],[23, 11]]
I need to multiply each 1 dimensional array in above array with the matrix.
For instance,
[1, 2] multiply with [a b]
[3, 4] multiply with [a b]
[5, 6] multiply with [a b]
[23, 11] multiply with [a b]

So, each 1 dimensional array in there will be multiplied with matrix [a b]
(same with matrix multiplication).

I can figure out how to do that multiplication in java. But I confuse how to 'release' each 1 dimensional array from the first array so I can do multiplication.
How to do that in java?
+Pie Number of slices to send: Send
No, there is no such thing as a 2‑D array in Java®. You have an array of arrays. Each element is an array.
System.out.println(Arrays.toString(numbers[0])); // Won't work for a 0‑element array.
+Pie Number of slices to send: Send
That is a 2×1 matrix (or 1×2), not 2×2.
+Pie Number of slices to send: Send
 

Speaky Share wrote:I can figure out how to do that multiplication in java. But I confuse how to 'release' each 1 dimensional array from the first array so I can do multiplication.


I'm not quite sure what you mean by 'release'. If you want to keep a copy of the original array (maybe a good idea), then you need to copy it first (have a look at Arrays.deepCopy()). If not, then arrays are mutable, so simply assign the result to the original element.

HIH

Winston
Hey! You're stepping on my hand! Help me tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 494 times.
Similar Threads
Storing 2D into "1D"
An object to hold several arrays
Assign an Array to an Array Element
1D 2D array variables
BubbleSort on Matrix
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 02:42:58.