LabVIEW Idea Exchange

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

Allow "Reshape Array" to reshape n-dim array to 1D array without wiring "dimension size 0"

Status: New

A lot of times I generate 1D arrays in each iteration of a for loop. Rather than concatenating the arrays inside the for loop I use and indexed output tunnel which gives me a 2D array. Using the Reshape Array function this can be reshaped into a 1D array essentially concatenating the 1D arrays together.

 

My problem is that the "dimension size 0" input of the Reshape Array function is required. I suggest that if this input is not wired to simply interpret the n-dim array as a 1D array.

 

ReshapeArray.png

 

Interestingly enough in the context help for Reshape Array "dimension size 0" is not shown in bold so it should not be required.

 

ReshapeHelp.PNG

7 Comments
RavensFan
Knight of NI

hfettig wrote:

 

Interestingly enough in the context help for Reshape Array "dimension size 0" is not shown in bold so it should not be required.

 

ReshapeHelp.PNG


On the other side of this, the Index Array function's context help shows Index 0 in bold meaning it would be required when it is actually not required on any index array functions.  Of course that is a more complicated example because what you get out depends on the N dimension of the array and whether you wire any row vs. col. vs. page vs. ...... indices.

tst
Knight of NI Knight of NI
Knight of NI
I don't think I would vote for this, not because it's wrong, but because it's relatively a corner case. To solve the problem in your example I would prefer my concat indexing suggestion, which has advantages in additional cases.

___________________
Try to take over the world!
PJM_Labview
Active Participant
I can see where this would be useful, but maybe a new primitive called "flatten to 1D array" might be more useful and potentially less confusing.


  


vipm.io | jki.net

altenbach
Knight of NI

I agree that the "concat indexing suggestions" mentioned by tst is more functional if the multidimensional array is a direct result of a autoindexing output tunnel. This is not always the case and thus I support this idea here.

 

I am a big supporter of optional inputs if a good default value is defined if left unwired. The most intuitive and obvious for reshaping a multidimensional array to a 1D array is reshaping without padding or dropping any elements, i.e. a 1D array where the size is the product of the dimensions.

BruceAmmons
Trusted Enthusiast

Could this work in the other direction as well?  What if I have a 1D array that I know is some multiple of 5.  Right now, I have to get the length, divide by 5, then use that as the second index.  It would be nice to be able to leave that second index blank and let LV figure out what the dimensions of the array should be.  If the original array is not a multiple of 5, it could round up so that all the data is retained.

 

Similarly, you could convert to an N dimension array and leave one input blank for LV to figure out.

 

Bruce

Bruce Ammons
Ammons Engineering
smmarlow
Member

Kudos to this idea.  It's an old one, but needs to be implemented.  The most common use of the reshape array function is for flattening to a 1D.  

Verywiseguy
Member

Kudos. When I was first learning LabVIEW, I thought the Reshape array function should work exactly like it is suggested to work here. When It didn't work like that, a google search lead me to this idea and hfettig's figure taught me how I actually needed to use Reshape array.

 

I still think Rehsape array's default action should be to flatten the input array into a single long 1D array. It's a common enough use case (personally the only use case I've ever had) that wiring up the array size and product nodes feels like extra work, and takes up extra space on the BD.

 

In newer Labview versions (2012 and onward), an alternative might be to put the 2D array through a for loop, index the inputs, and concatenate index the outputs. Reshape array might be far more efficient than that though, so this idea still had all my kudos..