How to extract a 1D array from N-dimensional array?

Kelvin Stott

Active Member
Joined
Oct 26, 2010
Messages
338
Hello,

I have a N-dimensional array called "Data", where the number of dimensions N is variable...

How can I extract a 1-dimensional array from this, comprising all elements along the Xth dimension, which are the first element along all the other dimensions?

For example, this would be equivalent to taking the values along one edge of a cubic 3D array, by specifying one of the 3 dimensions as X.

Thanks indeed for any help.

Kelvin
 
Last edited:
You would also need to specify the values for all but one of the dimensions:

Function SuperDuperIndex(myArray, ParamArray aviDim as Variant)

... where aviDim is an N-element array that contains the fixed values of all but one dimension and one special value (Empty, maybe) that indicates the 'stripe'
 
Last edited:
Upvote 0

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
You cannot get a 1D array by specifying 1 dimension of a N dimension array. You get an array of dimension N-1.

For example, in a 3D array, if you specify the value of 1 dimension, you get a 2D matrix.

Hello,

I have a N-dimensional array called "Data", where the number of dimensions N is variable...

How can I extract a 1-dimensional array from this, comprising all elements along the Xth dimension, which are the first element along all the other dimensions?

For example, this would be equivalent to taking the values along one edge of a cubic 3D array, by specifying one of the 3 dimensions as X.

Thanks indeed for any help.

Kelvin
 
Upvote 0
Hi Tushar, I only want the first element of every other dimension, so I will end up with a 1D array, rather than N-1...
 
Upvote 0
I'm trying to write a stand-alone function, where the input variable is an N-dimensional array:

Function GET1DARRAY(NArray, X)

I also have another function NDIM which can count the number of dimensions N in NArray, but from there I get stuck...

Kelvin, The function I suggested should do what you describe. Did you try it?
 
Upvote 0
Hi Jerry,

Sorry I missed your post (too many replies at once), let me take a closer look at this and see if I can get it to work, thanks.
 
Upvote 0
Maybe I am being particular dense but I still don't understand how "the first element of every other dimension" results in a 1D array. Take a 3D array. Suppose you specify element 2 of the 3rd dimension. This gives me a 2D array. What does "the first element of every dimension mean? I don't know what that means since you have to specify *two* indices to get any value!

Let's try this. Given that the 27 elements of a 3D array are indexed as below, which elements would constitute the 1D array of interest if I specify the index 3 value of 2?

0 0 0
0 0 1
0 0 2
0 1 0
0 1 1
0 1 2
0 2 0
0 2 1
0 2 2
1 0 0
1 0 1
1 0 2
1 1 0
1 1 1
1 1 2
1 2 0
1 2 1
1 2 2
2 0 0
2 0 1
2 0 2
2 1 0
2 1 1
2 1 2
2 2 0
2 2 1
2 2 2

Hi Tushar, I only want the first element of every other dimension, so I will end up with a 1D array, rather than N-1...
 
Upvote 0
Hi Tushar,

The easiest way to think of this is selecting one edge (1-dimensional array) of an N-dimensional polygon, which passes through the origin, by specifying one dimension X.
 
Upvote 0
Taking a 3-D array as an example, how would you specify which of the 8 edges to retrieve? One way (that has been suggested repeatedly) is to specify the fixed values of two of the dimensions, while the third dimension varies over its range. More generally, for an N-D cube, you would specify all but one dimension. That method is also constructive, since it's the way you index the array.

What's the alternative?
 
Upvote 0
For example:

For the 1st dimension (X=1) of a 3D array (N=3), the 1D array would be: [all, 1, 1]
For the 2nd dimension (X=2) of a 3D array (N=3), the 1D array would be: [1, all, 1]

For the 1st dimension (X=1) of a 4D array (N=4), the 1D array would be: [all, 1, 1, 1]
For the 3rd dimension (X=3) of a 4D array (N=4), the 1D array would be: [1, 1, all, 1]

For the 8th dimension (X=8) of a 24D array (N=24), the 1D array would be: [(1,)x7, all, (1,)x16]

Does that make sense now?
 
Upvote 0
Taking a 3-D array as an example, how would you specify which of the 8 edges to retrieve? One way (that has been suggested repeatedly) is to specify the fixed values of two of the dimensions, while the third dimension varies over its range. More generally, for an N-D cube, you would specify all but one dimension. That method is also constructive, since it's the way you index the array.

What's the alternative?

That was my understanding of the OP question. The OP further said that each fixed index would be the first element (LBound) of that dimension.
For Tushar's example, the result of having X=2 would be a 1-Dim array having the values found at these indicies of the 3-Dim array.
0 1 0
0 2 0
0 3 0
 
Upvote 0

Forum statistics

Threads
1,216,085
Messages
6,128,733
Members
449,465
Latest member
TAKLAM

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top