Visit Jeremy's Blog.
 Home Forums HCL Reviews Tutorials Articles Register Search Today's Posts Mark Forums Read
 LinuxQuestions.org array logical operations in python?
 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

 05-12-2005, 03:00 PM #1 zero79 Member   Registered: Nov 2003 Location: Ohio Distribution: Debian Unstable Posts: 460 Rep: 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.
 05-12-2005, 03:14 PM #2 zero79 Member   Registered: Nov 2003 Location: Ohio Distribution: Debian Unstable Posts: 460 Original Poster Rep: 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)```
 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: 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

 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 Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post frankie_DJ Programming 12 10-20-2005 03:39 AM zero79 Programming 0 08-31-2005 05:25 PM inspleak Programming 2 03-10-2004 02:24 PM davi_cabral Linux - Newbie 1 09-26-2003 11:04 AM dbeyes Linux - Newbie 1 04-22-2003 06:09 PM

LinuxQuestions.org

All times are GMT -5. The time now is 09:10 PM.

 Contact Us - Advertising Info - Rules - LQ Merchandise - Donations - Contributing Member - LQ Sitemap -