LabVIEW Idea Exchange

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

Add a Terminal that Defines Default Data for Reshape Array

Status: New

Currently, when you use the Reshape Array primitive, if new elements are created, they are filled with the default data of the datatype. Alternatively, allow a terminal that defines the fill value.

 

CurrentReshapeArray.png

9 Comments
JackDunaway
Trusted Enthusiast
In the meantime, can someone suggest an alternative that does not involve n-dimension nested For Loops?
Message Edited by JackDunaway (mechelecengr) on 09-06-2009 05:03 PM
RavensFan
Knight of NI

1.  Initialize array same size as your starting array with the desired default value.  (-1)

2.  Reshape this array in the same manner as you are doing above.  This will give you all -1's, in the initial elements, all 0's in the "new" elements

3.  Take your initial default (-1) and subtract the array in #2.  Now you have zero's in all the  initial elements, and the desired default in all the new elements.

4.  Add this array to the array as it shows in you current screen shot above.

JackDunaway
Trusted Enthusiast

Thanks a ton for the input, Ravens! For a sec, I was thinking you had uploaded a really crummy jpeg compression, but then realized that you have constant folding turned on.

 

Here are some problems I have with this approach:

 

1. Will not work when filling with NaN

2. Causes an extra data copy to be made that is as large as the output array

3. Potentially not compatible with strings/clusters

4. It's not readily evident what is going on here - all that's needed is a reshaped array with a specified fill, but we get some "complex" code for that "simple" task

 

I'm really not picking on Ravens... I can't imagine someone could come up with more elegant code (ahem, altenbach) with the toolset LabVIEW has to offer for this simple task. All I wanted to point out, however, is that this simple task becomes both obfuscated and a minor programming hurdle without a "Fill" parameter on the Reshape Array primitive.

Darin.K
Trusted Enthusiast

For this particular case (1D to 2D reshape) I have used the following to add NaN

 

ReshapeArray.jpg

JackDunaway
Trusted Enthusiast

The biggest advantage of having this feature built-in to the primtive is inherent polymorphism.

altenbach
Knight of NI

Here's what I probably would do....

 

 

I agree, a terminal to define the default pad value would be nice. I would prefer the connector on top, though.

JackDunaway
Trusted Enthusiast

@altenbach wrote:
Here's what I probably would do....

Altenbach's Proverbial Postage Stamp Block Diagram strikes again.

 

Here's where the Chameleon/Shapeshift/Type-Adapting VI capability would come in handy (even though, you would have to write a new VI for each output dimensionality).

ATE1978
Member

Reshape 1D array to 2D array, and change new elements to -1.png

wiebe@CARYA
Knight of NI

Of course all solutions only work when reshaping to a two dimensional array. They can easily be adapted, but the nr of destination dimensions will always be static. So a .vim will never work. A XNode might, but adding an input will be much more convenient. (Anything will be more convenient than an XNode.)

 

A 10 years late +1 from me.