[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Problem with large array
From: |
ahowe42 |
Subject: |
Re: Problem with large array |
Date: |
Wed, 21 Mar 2012 01:09:34 -0700 (PDT) |
If at anyway possible, I ALWAYS preinitialize arrays. Doing so should make
your code faster and more efficient 90% of the time (imho). Here's what I
would do, keeping the loop:
1) preinitialize X_big & Y_big using /zeros(nm,np)/ and a counter /copcnt =
0;/
2) inside the innermost if branch do this:
/this_row = [features(m_counter, :), Y'(p_counter,:) ];
X_big(copcnt+=1,:) = thisrow
Y_big(copcnt) = Y(m_counter, p_counter);/
3) after the loop
/X_big = X_big([1:copcnt],:); Y_big = Y_big([1:copcnt],:);/
All that said, there should be a way to do this without looping, or at the
very least with a single loop. Vectorization of operations is another thing
that almost always improves code; except where functionality depends on
*successive* operations, vectorization is usually possible.
Andrew
--
View this message in context:
http://octave.1599824.n4.nabble.com/Problem-with-large-array-tp4488957p4491555.html
Sent from the Octave - General mailing list archive at Nabble.com.