cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X

How best to convert an array with subarrays into an array without subarrays?

FredLusk
12-Amethyst

How best to convert an array with subarrays into an array without subarrays?

The attached Prime 3.0 worksheet is a simplified version of what I am trying to do. I am working on a fairly lengthy program function that will accept single-column input arrays (vectors) of varying lengths (or even just a single number) and output an array with several elements. Input/output-wise, it is no different than the simple example in the attached worksheet.

When I use the whole data array as the input, the output is an array with vertical subarrays for the three columns. When I use the data array one element at a time (range variable), the output is an array with horizontal subarrays for the rows. This makes sense to me, but it's not quite what I want. What I really want is a single array without subarrays so I can do other things with the output more easily. I don't see that Prime 3.0 has a simple function to "un-subarray" an array.

I need some ideas on the best / most efficient / most elegent method for producing a single array from an array with subarrays.

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions

So here is what I came up with (not that I would think that its any better than what Stuart had provided).

View solution in original post

4 REPLIES 4

Here is on way to do it but I don't think ist the "most elegant" as I don't like to use the ranges for that purpose.

I'd rather prefer using a program which will take the nested matrix which a vectorized call would return and calculates and returns the unnested matrix.

But as a quick hack this appraoch may suffice:

1.png

EDIT: Just noticed - you can omit the vectorization in that appraoch as you are only passing a signle scalar as argument.

StuartBruff
23-Emerald II
(To:FredLusk)

Fred Lusk wrote:

The attached Prime 3.0 worksheet is a simplified version of what I am trying to do. I am working on a fairly lengthy program function that will accept single-column input arrays (vectors) of varying lengths (or even just a single number) and output an array with several elements. Input/output-wise, it is no different than the simple example in the attached worksheet.

When I use the whole data array as the input, the output is an array with vertical subarrays for the three columns. When I use the data array one element at a time (range variable), the output is an array with horizontal subarrays for the rows. This makes sense to me, but it's not quite what I want. What I really want is a single array without subarrays so I can do other things with the output more easily. I don't see that Prime 3.0 has a simple function to "un-subarray" an array.

I need some ideas on the best / most efficient / most elegent method for producing a single array from an array with subarrays.

Thanks.

I had a function knocking around that did this .. used it for a prototype Multi-Dimensional Array worksheet that attempted to emulate Mathematica's array handling.

However, it doesn't appear to be on my work PC, so I've flung this one together (tacked on to the end of the createspace worksheet just to easily generate some test data).

I seem to recall that the original function handled nested matrices in some fashion as well, but I don't have time to implement it now.

Stuart

Unfortunately, I don't have Prime, but you should be able to import it.

collab - 14 12 19 Flattening Regularly Nested Vectors 01.JPG

FredLusk
12-Amethyst
(To:FredLusk)

Thanks to both you. I will give these a whirl.

So here is what I came up with (not that I would think that its any better than what Stuart had provided).

Top Tags