annulla
Visualizzazione dei risultati per 
Cerca invece 
Intendevi dire: 

2D to 3D array

Risolto!
Vai alla soluzione

I have a 2D array of integers such as

 

1,1,1

1,2,2

1,3,3

2,1,0

2,2,0

3,3,0

 

I want to create a 3D array such that

page0 =

1,1,1

1,2,2

1,3,3

 

page1=

2,1,0

2,2,0

 

page2=

3,3,0

 

I am not sure what is the best approach to doing this.

 

0 Kudos
Messaggio 1 di 14
6.521Visualizzazioni

Impossible. All pages must be 2D arrays of the same size.

 

(You could make a 1D array of clusters where each cluster contains a 2D array, representing a page.)

Messaggio 2 di 14
6.520Visualizzazioni

I can live with pages of equal sizes.

For the above data set, the 2D array will be 3x3.

 

Is there a way to do this?

 

0 Kudos
Messaggio 3 di 14
6.512Visualizzazioni

Does the first element (minus 1) represent the page?

What if there are more than three rows with the same page number?

Are the rows always sorted by the first element?

 

I would initialize a 3D array with all zero (or even NaN), place it in a shift register, then loop over the 2D input array, replacing one page row at a time.

0 Kudos
Messaggio 4 di 14
6.505Visualizzazioni
Soluzione
Accettato da autore argomento nyc_(is_out_of_here)

Split your 2D-array at row indices 2 and 4, giving you 3 new 2D-arrays. pass these on to a 'build array' (right click and make sure it does not concatenate inputs), giving you a 3D-array.

 

If you dont want each page of the same size, bundle each 2D-array into a cluster before building the new array, effectively giving you a 1D-array of clusters containing 2D-arrays, as Altenbach suggested.



CLA
https://www.prevas.se/expertis/test--regulatoriska-krav.html
0 Kudos
Messaggio 5 di 14
6.503Visualizzazioni

@M_Peeker wrote:

Split your 2D-array at row indices 2 and 4, giving you 3 new 2D-arrays. pass these on to a 'build array' (right click and make sure it does not concatenate inputs), giving you a 3D-array.

 

 


Visually I can see that I need to split my 2D-array at row indices 2 and 4, but I want to do this programmatically.

 

With another set of data, the row indices may be at 5 and 7.

 

Is there a fast way of doing this?

0 Kudos
Messaggio 6 di 14
6.497Visualizzazioni

@altenbach wrote:

Does the first element (minus 1) represent the page?

What if there are more than three rows with the same page number?

Are the rows always sorted by the first element?

 

I would initialize a 3D array with all zero (or even NaN), place it in a shift register, then loop over the 2D input array, replacing one page row at a time.


No, the first element does not repesent the page number. I can see how they can be construed that way though.

 

The rows are already sorted when they get to this VI I am trying to write.

 

0 Kudos
Messaggio 7 di 14
6.494Visualizzazioni

Not fast maybe, but this should work, providing you know the indices where to split (they should be 3 and 5 in your example it turns out).Split2DArrays.png



CLA
https://www.prevas.se/expertis/test--regulatoriska-krav.html
0 Kudos
Messaggio 8 di 14
6.478Visualizzazioni

If the row to page/row mapping is constant, just use diagram constants, e.g. as follows.

 

 

0 Kudos
Messaggio 9 di 14
6.477Visualizzazioni

nyc wrote:With another set of data, the row indices may be at 5 and 7.

OK, so the output array is not necessarily 3x3?

I think all you need to do is use a FOR loop with N=number of pages.

Inside the FOR loop, take the various subsets.

The 3D array will automatically pad to the largest 2D array subset once you autoindex at the output tunnel.

Messaggio 10 di 14
6.473Visualizzazioni