10-23-2008 10:58 AM
I am trying to use the Standard Deviation PtbyPt Vi. It takes in a series of points, can be reset when beginning the calculation. There is also an input for sample size. I am calculating some statistics on an array...and would only to include like the non-zero elements that are in the sample.
Is there a quick way to look at an array and find the number of non-zero elements?
Thanks.
Solved! Go to Solution.
10-23-2008 11:03 AM - edited 10-23-2008 11:03 AM
Hi Hummer,
test the array for "unequal to 0", convert the resulting boolean array to numbers and sum up the array. Just three LabView primitives.
Be aware:
- for big arrays you need an additional step of converting the numbers array to I32 before summing up
- for big arrays this may lead to "out of memory" problems because of creation of data copies
10-23-2008 12:41 PM
Well, now that I have tried to do this I am confused. I guess I need a little help.
Do you have to step through the 2x2 array using indexing on and do element by element comparison before going on...or do you first do the not equal 0 to build an array of boolians...and then count the boolians by using a select in an nxn do loop....
A hint would be appreciated.
10-23-2008 01:11 PM
Most LabVIEW primitives are polymorphic. This means they automatically adapt to the datatype wired to them. Wire a scalar, get a scalar. Wire an array, get an array. Try it.
To learn more about LabVIEW it is recommended that you go through the tutorial(s) and look over the material in the NI Developer Zone's Learning Center which provides links to other materials and other tutorials. You can also take the online courses for free.
10-23-2008 01:24 PM
One example of the polymorphism smercurio mentioned...
10-23-2008 01:58 PM - edited 10-23-2008 01:59 PM
GerdW wrote:- for big arrays this may lead to "out of memory" problems because of creation of data copies
Here's a quick rundown on memory allocations based on the algorithm.
(case 1&3)
If you do the "!=0, ?1:0, I32, sum" shuffle, each step needs to allocate a new array, so if the input array is DBL and uses N amount of memory, we need 7N/8 more memory.
(Total of 15N/8, or 13N/8 if we don't need the I32, but in this case the array are too small to worry about anything ;))
The nice thing is that it works for any array dimensionality (1D, 2D, 5D, etc...)
(Case 2&5)
If you do the summing in a shift register, No additional array memory is needed. Unfortunately, the code needs to be changed by adding an extra FOR loop for each dimension (see case 5 for 2D inputs).
(Case 4)
If we reshape the N-D array to a 1D array, we need to create a second copy, so the memory usage is about twice. This also works for any dimension.
In real life, and if memory is a potential issue, you should always do some benchmarks.
Often, the issues are more complex, so this is just a quick summary.
10-23-2008 02:25 PM
Case 5 is what I was trying to noodle out. Although case 3 is certainly simple.
Thanks a million to all...
03-27-2015 10:56 AM
I am trying to add the number of ones . I did exactly as you said but still it is not working?
Could you please navigate me?
BR
Fatemeh
03-27-2015 10:59 AM
Hi
I did exactly as you said but it is not working. I want to add the number of ones in array.
Could you please help me .
03-27-2015 11:35 AM