# [Numpy-discussion] 3D array problem in Python

Raul Cota raul@virtualmaterials....
Mon Dec 31 12:42:17 CST 2012

```Quick comment since I was working on timing trivial operations,

If I run the triple loop with R with only zeros thus avoiding the
integration, the loop takes in my computer about 1 second with the
float() function and about 1.5 without it if R is dtype='float64' and
3.3 seconds if dtype='float32'.

I didn't bother trying the other obvious speed up of avoiding the dot
operator

and using quad inside the triple loop.

I do those things out of habit but they barely ever make a meaningful
difference.

Conclusions:
1) The overhead of the triple loop is meaningless if the whole operation
takes minutes to complete.

2) Using float() does make it faster but in this scenario the speed up
is meaningless in the grand scheme of things.
* It is besides the point, but for what is worth, with the modified code
for numpy I suggested a week ago, using the float() function is not
needed to get it to run in 1 second.

Raul Cota

On 30/12/2012 5:35 PM, Chris Barker - NOAA Federal wrote:
> On Sun, Dec 30, 2012 at 3:41 AM, Happyman <bahtiyor_zohidov@mail.ru> wrote:
>> nums=32
>> rows=120
>> cols=150
>>
>> for k in range(0,nums):
>>            for i in range(0,rows):
>>                       for j in range(0,cols):
>>                                        if float ( R[ k ] [ i ] [ j ] ) ==
>> 0.0:
> why the float() -- what data type is R?
>
>>                                        else:
>>                                                   val11[ i ] [ j ], val22[ i
>> ][ j ] = integrate.quad( lambda x :  F1(x)*F2(x) , 0 , pi)
> this is odd -- Do F1 and F2 depend on i,j, or k somehow? or are you
> somehow integerting over the k-dimension? In which case, I'm guessing
> that integration is you time killer anyway -- do some profiling to
> know for sure.
>
> -Chris
>

```