Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Java in General
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Java in General
Subtract 3D matrix from 2D
nvayin agha
Greenhorn
Posts: 16
posted 7 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I have the code bellow which is for subtracting 3D Matrix from 2D , iam receiving error : Array index out of bound
import java.util.*; class test28{ public static void main ( String[] args ) { int [][][] arr1 = {{{6,3,9,0},{8,6,5,3},{5, 4, 6, 7}}}; int [][] arr2= {{6,3,5,0},{8,6,5,3}}; test28 test = new test28(); System.out.println(Arrays.deepToString(test.subtract(arr1,arr2))); } public static int [][] subtract(int[][][] a, int[][] b) { int[][] diff = new int[a[0].length][a[0][0].length]; for ( int j=0; j<a[0].length; j++){ for ( int k=0; k<a[0][0].length; k++){ diff[j][k] = a[0][j][k]- b[j][k]; } } return diff; } }
any help please
Piet Souris
Bartender
Posts: 5465
212
posted 7 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
hi nvayin,
how do you debug your programs?
If you look at the dimensions of the 2D arrays arr1[0] and arr2, you see that arr1[0] is 3 * 4, while arr2 = 2 * 4.
So, you get this error on arr2 in your
test
method.
There are three kinds of actuaries: those who can count, and those who can't.
nvayin agha
Greenhorn
Posts: 16
posted 7 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
The data that i have have these format:
a[][][]:
3.551777347914275 1.286875832907195
8.513771304610692 3.084699705412586
5.896962960211207 2.1365807531547536
6.477661799763445 2.346978880519314
7.447357702484369 2.6983179708520675
5.156151670042258 1.8681708691221717
and b[][]:
1.4 0.2
1.4 0.2
1.3 0.2
1.5 0.2
1.4 0.2
1.7 0.4
1.4 0.3
those are my data which i should use the method subtract on them
Piet Souris
Bartender
Posts: 5465
212
posted 7 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
By the look of it, a = 3 x 2 x 2, and b = 7 x 2.
How would you subtract one from the other?
Can you explain what it is you are trying to achieve?
There are three kinds of actuaries: those who can count, and those who can't.
Don't get me started about those stupid
light bulbs
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Subtract Three dimention array from 2D
Multiply 3D matrix
How to return the sum of a multi dimensional array?
Copy Array in special format
How can I get the unmatched values from two arrays
More...