LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 05-12-2005, 03:00 PM   #1
zero79
Member
 
Registered: Nov 2003
Location: Ohio
Distribution: Debian Unstable
Posts: 460

Rep: Reputation: 30
Question array logical operations in python?


Hi all,

Are there any python libraries that implement functionality similar to logical array operations in MATLAB? For example in matlab

Code:
x = 1:10
x(x>5) = 0
will output

Code:
x =

  1  2  3  4  5  0  0  0  0  0
where x>5 gives the logical array where x is greater than 5

Code:
x>5 =
  0 0 0 0 0 1 1 1 1 1
I know I can accomplish the same goal with for/if/else, but array operations should be significantly faster. Thanks for any thoughts.

Last edited by zero79; 05-12-2005 at 03:02 PM.
 
Old 05-12-2005, 03:14 PM   #2
zero79
Member
 
Registered: Nov 2003
Location: Ohio
Distribution: Debian Unstable
Posts: 460

Original Poster
Rep: Reputation: 30
Ok, I think I found what I am looking for

Code:
#!/usr/bin/python

from Numeric import *
x = array((1,2,3,4,5,6,7,8,9,10))
print where(greater(x,5),x,0)
 
Old 05-13-2005, 03:56 AM   #3
ag2uki
Member
 
Registered: Oct 2004
Location: Yogyakarta, Indonesia
Distribution: Mandrake 9.0, 9.1, 9.2, 10.0
Posts: 84

Rep: Reputation: 16
It could be like this....

x = range(1,10)
x = [j for j in (x[:5]+[0 for k in range(4)])]



regards
Agus Dwi Basuki
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
C++:Operations with iterators frankie_DJ Programming 12 10-20-2005 03:39 AM
Best Python float array library? zero79 Programming 0 08-31-2005 05:25 PM
PERL: Size of an array of an Array inspleak Programming 2 03-10-2004 02:24 PM
Aritmethical operations davi_cabral Linux - Newbie 1 09-26-2003 11:04 AM
Modem operations dbeyes Linux - Newbie 1 04-22-2003 06:09 PM


All times are GMT -5. The time now is 07:45 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration