[SciPy-User] 3D array problem in Python
Thøger Rivera-Thorsen
thoger.emil at gmail.com
Sun Dec 30 12:11:16 EST 2012
By the way;
I don't know if they are useful to you, but here are some introductory
slides from a workshop I gave for our undergraduate studemts at
Stockholm University. The Python part starts at slide 18.
Emil
On 12/30/2012 05:16 PM, Happyman wrote:
> Hi
>
> Thanks for your answer... I also tried to do so unfortunately I could
> not manage that because of no very good experience in Python...
> The way you propose is really good indeed but how can i do it???
>
> Two huge problems I always encounter in Python are:
> 1) Array with scalars...always!!!!!
> 2) for loop I can understand Python is script language but how to
> deal with it???
>
> Especially, when I create some function in which arguments can take
> one value are messed up with negotiation wit outer coming variables
> into my function!!
> for example,
> arg1, arg2 are arrays!
> def f( arg1, arg2 ):
> some process, loops everthing
> return val
>
>
>
>
>
> Воскресенье, 30 декабря 2012, 16:47 +01:00 от Thøger Rivera-Thorsen
> <thoger.emil at gmail.com>:
>
> Use np.where() or logical indexing (same thing, really) to mask
> your array, then perform the operations. Let's say your array is
> called A:
>
> A[float(A) == 0.0] = 0.0
>
> A[float(A) != 0.0] = [...etc.]
>
>
> This, of course, only works if the operation for an entry doesn't
> depend on other entries in the array; but it should give you a
> great speed gain.
>
> Cheers;
>
> Emil
>
>
>
> On 12/30/2012 04:32 AM, Happyman wrote:
>> 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 at scipy.org <sentmsg?mailto=mailto%3aSciPy%2dUser at 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/69720c08/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Tools-Print-OneOnOne.pdf
Type: application/pdf
Size: 1847695 bytes
Desc: not available
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20121230/69720c08/attachment.pdf>
More information about the SciPy-User
mailing list