bradjb911 Posted April 23, 2009 Report Share Posted April 23, 2009 Hello, I am working to build a data analysis system and having a little trouble with the arrays. I just want to reduce the data like below. Example 2D array: [ 1 3 5 7 2 4 6 8 1 3 5 7 ] Into 1D Array: [ 1 3 5 7 2 4 6 8 1 3 5 7 ] I've been working on this for a couple of hours and it seems like a simple problem, but I'm not beating it yet. Thanks, Brad Quote Link to comment
Grampa_of_Oliva_n_Eden Posted April 23, 2009 Report Share Posted April 23, 2009 QUOTE (bradjb911 @ Apr 22 2009, 03:28 PM) Hello,I am working to build a data analysis system and having a little trouble with the arrays. I just want to reduce the data like below. Example 2D array: [ 1 3 5 7 2 4 6 8 1 3 5 7 ] Into 1D Array: [ 1 3 5 7 2 4 6 8 1 3 5 7 ] I've been working on this for a couple of hours and it seems like a simple problem, but I'm not beating it yet. Thanks, Brad Use re-shape array? Multiple the dimensions of your 2d and use that value to spec the size of the 1-d array. Ben Quote Link to comment
crossrulz Posted April 23, 2009 Report Share Posted April 23, 2009 QUOTE (bradjb911 @ Apr 22 2009, 03:28 PM) Hello,I am working to build a data analysis system and having a little trouble with the arrays. I just want to reduce the data like below. Example 2D array: [ 1 3 5 7 2 4 6 8 1 3 5 7 ] Into 1D Array: [ 1 3 5 7 2 4 6 8 1 3 5 7 ] I've been working on this for a couple of hours and it seems like a simple problem, but I'm not beating it yet. Thanks, Brad Reshape array as shown below. I already tried the code and it works fine. In fact, I've been thinking of making this very function for my user library. http://lavag.org/old_files/monthly_04_2009/post-11268-1240432043.png' target="_blank"> Quote Link to comment
PaulG. Posted April 23, 2009 Report Share Posted April 23, 2009 QUOTE (crossrulz @ Apr 22 2009, 04:28 PM) Reshape array as shown below. I already tried the code and it works fine. In fact, I've been thinking of making this very function for my user library. That's the way I do it. OpenG has Reshape that's kind of slick, too. http://lavag.org/old_files/monthly_04_2009/post-3786-1240433063.png' target="_blank"> Quote Link to comment
Grampa_of_Oliva_n_Eden Posted April 23, 2009 Report Share Posted April 23, 2009 QUOTE (crossrulz @ Apr 22 2009, 04:28 PM) Reshape array as shown below. I already tried the code and it works fine. In fact, I've been thinking of making this very function for my user library. http://lavag.org/old_files/monthly_04_2009/post-11268-1240432043.png' target="_blank"> THe multiply array operator can replace the index and multiply code. Ben Quote Link to comment
asbo Posted April 23, 2009 Report Share Posted April 23, 2009 Maybe I'm not thinking in G enough, but I would have just used an indexed For loop with a shift register and a Build Array. Your solutions are a little more concise, though. Quote Link to comment
crossrulz Posted April 23, 2009 Report Share Posted April 23, 2009 QUOTE (neBulus @ Apr 22 2009, 04:47 PM) THe multiply array operator can replace the index and multiply code.Ben Dude, I have done this operation (index and multiply) so many times and not once did I even think of the Multiply Array. That will make it better. Quote Link to comment
crelf Posted April 23, 2009 Report Share Posted April 23, 2009 QUOTE (asbo @ Apr 22 2009, 05:34 PM) ...but I would have just used an indexed For loop with a shift register and a Build Array. You mean "created an array with the appropriate number of elements outside a for loop, then replaced it's values", right? Quote Link to comment
ShaunR Posted April 24, 2009 Report Share Posted April 24, 2009 QUOTE (neBulus @ Apr 22 2009, 09:47 PM) THe multiply array operator can replace the index and multiply code.Ben And means that you can convert n-dimensional arrays Quote Link to comment
Grampa_of_Oliva_n_Eden Posted April 24, 2009 Report Share Posted April 24, 2009 QUOTE (crelf @ Apr 22 2009, 06:24 PM) You mean "created an array with the appropriate number of elements outside a for loop, then replaced it's values", right? In modern versions* of LV that is a waste of time. The for loop does that "for" you behind the scenes. Yes I have tested it. No, I don't have the benchmarks handy to prove it. Ben * I think this came in at version 6 with all of the "optimization" that came with that release. Quote Link to comment
asbo Posted April 24, 2009 Report Share Posted April 24, 2009 QUOTE (crelf @ Apr 22 2009, 06:24 PM) You mean "created an array with the appropriate number of elements outside a for loop, then replaced it's values", right? QUOTE (neBulus @ Apr 23 2009, 06:45 AM) In modern versions* of LV that is a waste of time. The for loop does that "for" you behind the scenes. In either case, I would leave it up to the developer to decide whether the data structure is large enough to necessitate that. If you keep giving out complete answers like that, crelf, you might find yourself out of work ... Quote Link to comment
crelf Posted April 24, 2009 Report Share Posted April 24, 2009 QUOTE (neBulus @ Apr 23 2009, 06:45 AM) In modern versions* of LV that is a waste of time. The for loop does that "for" you behind the scenes. Yes I have tested it. No, I don't have the benchmarks handy to prove it. Maybe we're talking about different things, but I don't beleive you There's no way for the For Loop to know how many elements are going to be in the array, so how can it do an optimization like that? http://en.wikiquote.org/wiki/Linus_Torvalds' rel='nofollow' target="_blank">Linus Torvalds: Talk is Cheap. Show me the Code. Quote Link to comment
Gary Rubin Posted April 24, 2009 Report Share Posted April 24, 2009 QUOTE (crelf @ Apr 23 2009, 10:13 AM) There's no way for the For Loop to know how many elements are going to be in the array... If the loop is indexed, there sure is a way for the loop to know. I'm sure I've read an app note for 7.1 that concurs with Ben's statement. Trying to find it now. EDIT: Here we go - app note 168: QUOTE If you want to add a value to the array with every iteration of the loop, you can see the best performance by using auto-indexing on the edge of a loop. With For Loops, the VI can predetermine the size of the array (based on the value wired to N), and resize the buffer only once. I don't know if something under the hood in LV has changed since then that makes the preallocate and replace faster. Quote Link to comment
crelf Posted April 24, 2009 Report Share Posted April 24, 2009 QUOTE (asbo @ Apr 23 2009, 09:18 AM) If you keep giving out complete answers like that, crelf, you might find yourself out of work ... It's all about tapping into the limitless power of communiity: Quote Link to comment
Grampa_of_Oliva_n_Eden Posted April 24, 2009 Report Share Posted April 24, 2009 QUOTE (Gary Rubin @ Apr 23 2009, 10:22 AM) If the loop is indexed, there sure is a way for the loop to know. I'm sure I've read an app note for 7.1 that concurs with Ben's statement. Trying to find it now.EDIT: Here we go - app note 168: I don't know if something under the hood in LV has changed since then that makes the preallocate and replace faster. Thank you Gary! Since we have wondered to the topic of performance I'll share my list of code construct choice from fastest to slowest where in/out arrays are the same size. LV Primative - Like the Multiply Array. For Loop - LV pre-allocates and replaces While Loop with Pre-allocated array - Fater because of no need to re-allocate more momory. While Loop no pre-allocate I am not usre about the For Loop with condition terminal but I'd gues it fits in after the For Loop but before the While Loop with pre-allocated buffer. Ben Quote Link to comment
crelf Posted April 24, 2009 Report Share Posted April 24, 2009 QUOTE (Gary Rubin @ Apr 23 2009, 10:22 AM) If the loop is indexed, there sure is a way for the loop to know preallocate and replace faster. <trying not be feel offended> Of course that's true when talking about about an array that is indexed by the loop </trying not be feel offended>, but my understanding was that we weren't talking about that - we were talking about an array where the size is not defined by the number of loop executions. Quote Link to comment
Gary Rubin Posted April 24, 2009 Report Share Posted April 24, 2009 QUOTE (crelf @ Apr 23 2009, 11:10 AM) <trying not be feel offended> Of course that's true when talking about about an array that is indexed by the loop </trying not be feel offended>, but my understanding was that we weren't talking about that - we were talking about an array where the size is not defined by the number of loop executions. Ah, good point. Quote Link to comment
bradjb911 Posted April 25, 2009 Author Report Share Posted April 25, 2009 Thanks you guys, you knocked the question out of the park. Brad Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.