Hi,
I understand you've simplified the example here, but just in case you did
not,
your integral does not depend on i,j or k, so you could calculate it only
once.
import numpy as np
a, b = integrate.quad( lambda x : F1(x)*F2(x) , 0 , pi)
val11 = np.array(val11)
val22 = np.array(val22)
R = np.array(R)
val11 = 0
val22 = 0
for k in range(nums):
nonz = R[k] > 0
val11[nonz] = a
val22[nonz] = b
Or if the above is not possible try this
pairs = [
[
[integrate.quad( lambda x : F1(x)*F2(x) , 0 , pi) if R[k][i][j] > 0 else
(0,0) for j in range(cols) ]
for i in range(rows)]
for k in range(nums)]
But then from pairs you have to work how to extract vals11 and vals22
HTH
Cheers
--
Oleksandr (Sasha) Huziy
2012/12/29 Happyman <bahtiyor_zohidov@mail.ru>
> Hello
>> I have 3 dimensional array which I want to calculate in a huge process.
> Everything is working well if I use ordinary way which is unsuitable in
> Python like the following:
>> 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:
> val11 [ i ] =0.0
> else:
> val11[ i ] [ j ], val22[
> i ][ j ] = integrate.quad( lambda x : F1(x)*F2(x) , 0 , pi)
>> But, this calculation takes so long time, let's say about 1 hour
> (theoretically)... Is there any better way to easily and fast calculate the
> process such as [ F( i ) for i in xlist ] or something like that rather
> than using for loop?
>>>>> _______________________________________________
> SciPy-User mailing list
>SciPy-User@scipy.org>http://mail.scipy.org/mailman/listinfo/scipy-user>>-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20121230/3cbf031e/attachment.html