I couldn’t live without “Filter 1D Array”

Posted on Sunday 8 April 2007

This is the fifth article of “The OpenG VIs that I couldn’t live without“, a series of articles showing some of my favorite OpenG VIs. In this article, I’m going to show a very useful VI, Filter 1D Array, that is used to filter items out of a 1D array.

Filter 1D Array

Let’s take a look at a couple simple examples of this VI in action.

In this example (shown below), we are filtering out all values of +Inf and -Inf from a 1D array of DBL floating point numbers. We simply specify an array of items that we wish to filter out of the input array and Filter 1D Array does the rest.

Filter 1D Array Example

In our next example (shown below) we will notice that Filter 1D Array is Polymorphic. First, we notice that this example is filtering items from an array of strings (or previous example used a DBL floating point array) and, second, we notice that we are wiring a scalar value (empty string) into the “items to filter” (our previous example used an array of items to filter). You can see in this example that all of the empty string elements were removed from the input array. Very cool!

Filter 1D Array by Scalar Example

One other thing that you should also know (that we did not highlight in the above examples), is that Filter 1D Array outputs an array of indices (pointers) of the items that were removed. This allows you to do operations on associative arrays (see wikipedia definition of associative array) — an advanced programming technique.

If you want to give this VI a try, you can obtain it using VI Package Manager (VIPM). Simply select the OpenG Array Library (the oglib_array package from within VIPM), you will find the OpenG Array Tools palette in the Functions palette under the OpenG submenu. (See here for a quick guide on how to install OpenG on VIPM.)

6 Comments for 'I couldn’t live without “Filter 1D Array”'

    April 9, 2007 | 10:23 am

    Nice article Jim. In array operations I think performance is an important issue at least in many of my own use cases. How well are these operations performing? It would be nice to see some performance measures in the context of OpenG VIs you introduce.

    April 9, 2007 | 10:30 am

    Tomi: Thanks for the feedback. Yes, performance is an important issue. Right now, we (OpenG) are not taking any performance metrics (but we do try very hard to write code that will execute efficiently). Ultimately, I would like to incorporate performance testing into the development and automated build process (FYI — in the past 6 months, we have just incorporated automated unit testing into the build process). It would be nice to take a look at performance metrics, especially when changes are made to the underlying implementation.

    April 11, 2007 | 11:00 am

    Hi Jim, Thanks for introducing the Filter 1D array. I’d like to propose an addition to the series of array filter operations. I think an ability to filter a string array based on regular expression would be nice. Second I’d like to see an additional input in all filter operations that would exclude the items that are now included. You are so good at writing these great OpenG VIs ;)

    April 11, 2007 | 11:24 am

    Tomi: Thanks for the feedback. Filtering an array by regular expression is on my to-do list. And, I agree that the ability to set the filtering mode as either block and pass is needed. I’ll see what I can do :)

    Şenol Özkan
    November 29, 2011 | 9:05 am

    Hello Jim!
    I know this is really old page but I was wondering if you have developed anything like Filtering mode as pass and filtering by regular expression.
    I have written a code that reads each row, checks the regexp and stores if it fits but it is extremely slow for arrays with thousands of rows. I was hoping that this Filter block is faster but without the pass and regular exp. option I cannot really use this either.

    July 28, 2017 | 1:42 am

    Скачай бесплатно и без регистрации,
    не каких СМС.

Leave a comment



Information for comment users
Line and paragraph breaks are implemented automatically. Your e-mail address is never displayed. Please consider what you're posting.

Use the buttons below to customise your comment.

RSS feed for comments on this post |


Bad Behavior has blocked 1123 access attempts in the last 7 days.