<div dir="ltr">Dear Peter<div><br></div><div style>Yes the f[t] or f[:,:,:] might give a marginal increase, but then i need to do further operations using the indices, in which case this wouldnt help</div><div style><br>
</div><div><br></div><div>Dear Wojciech<div><br></div><div style>np.flat() works if u dont care about the indices and only the matrix/array values matter.</div><div style>but if the <i,j,k> matters, flatten wouldnt work</div>
<div style><br></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Aug 6, 2014 at 1:34 PM, Wojciech Giel <span dir="ltr"><<a href="mailto:wojtekgiel@gmail.com" target="_blank">wojtekgiel@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">You might check numpy it is really powerful tool for working with multi dimensional arrays:<br>
<br>
ex.<br>
>>> a = arange(81).reshape(3,3,3,3)<br>
>>> a<br>
<br>
array([[[[ 0, 1, 2],<br>
[ 3, 4, 5],<br>
[ 6, 7, 8]],<br>
<br>
[[ 9, 10, 11],<br>
[12, 13, 14],<br>
[15, 16, 17]],<br>
<br>
[[18, 19, 20],<br>
[21, 22, 23],<br>
[24, 25, 26]]],<br>
<br>
<br>
[[[27, 28, 29],<br>
[30, 31, 32],<br>
[33, 34, 35]],<br>
<br>
[[36, 37, 38],<br>
[39, 40, 41],<br>
[42, 43, 44]],<br>
<br>
[[45, 46, 47],<br>
[48, 49, 50],<br>
[51, 52, 53]]],<br>
<br>
<br>
[[[54, 55, 56],<br>
[57, 58, 59],<br>
[60, 61, 62]],<br>
<br>
[[63, 64, 65],<br>
[66, 67, 68],<br>
[69, 70, 71]],<br>
<br>
[[72, 73, 74],<br>
[75, 76, 77],<br>
[78, 79, 80]]]])<br>
<br>
>>> f = a.flat<br>
>>> for i in f:<br>
... print(i)<br>
0<br>
1<br>
2<br>
..<br>
98<br>
99<br>
<br>
cheers<span class="HOEnZb"><font color="#888888"><br>
Wojciech</font></span><div class="HOEnZb"><div class="h5"><br>
<br>
<br>
<br>
On 05/08/14 21:06, Frank Miles wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I need to evaluate a complicated function over a multidimensional space<br>
as part of an optimization problem. This is a somewhat general problem<br>
in which the number of dimensions and the function being evaluated can<br>
vary from problem to problem.<br>
<br>
I've got a working version (with loads of conditionals, and it only works<br>
to #dimensions <= 10), but I'd like something simpler and clearer and<br>
less hard-coded.<br>
<br>
I've web-searched for some plausible method, but haven't found anything<br>
"nice". Any recommendations where I should look, or what technique should<br>
be used?<br>
<br>
TIA!<br>
</blockquote>
<br>
-- <br>
<a href="https://mail.python.org/mailman/listinfo/python-list" target="_blank">https://mail.python.org/<u></u>mailman/listinfo/python-list</a><br>
</div></div></blockquote></div><br></div>