473,385 Members | 1,317 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

array subset could be improved? -repost ;)

Hi all

I have an array a=array([2,3,-1]).

I want to extract an array with all the elements of a that are less than 0.

Method 1.
new = array([i for i in a if i < 0])

Method 2.
new = a[nonzero(a<0)]

I'm using Numeric arrays but can't seem to find a function that does this.

Am I missing a more obvious way to do it quickly?

Thanks

Jim
Oct 14 '05 #1
4 1806
jon

Jim O'D wrote:
Hi all

I have an array a=array([2,3,-1]).

I want to extract an array with all the elements of a that are less than 0.

Method 1.
new = array([i for i in a if i < 0])

Method 2.
new = a[nonzero(a<0)]

I'm using Numeric arrays but can't seem to find a function that does this.

Am I missing a more obvious way to do it quickly?

Thanks

Jim


Oct 14 '05 #2
jon

Jim O'D wrote:
Hi all

I have an array a=array([2,3,-1]).

I want to extract an array with all the elements of a that are less than 0.

Method 1.
new = array([i for i in a if i < 0])

Method 2.
new = a[nonzero(a<0)]

I'm using Numeric arrays but can't seem to find a function that does this.

Am I missing a more obvious way to do it quickly?

Thanks

Jim


a2=Numeric.compress(a<0,a)

Oct 14 '05 #3
Jim O'D wrote:
Hi all

I have an array a=array([2,3,-1]).

I want to extract an array with all the elements of a that are less than 0.


Numeric is currently changing into the new scipy core. If you are willing to
play with beta code, get it here:

http://numeric.scipy.org

if not, wait a little for an official release.

With the new numeric, you'll be able to do:

negatives = a[a<0]

Cheers,

f

Oct 14 '05 #4
With the new numeric, you'll be able to do:

negatives = a[a<0]

Cheers,

f


Ooh, that's nice.

Jim
Oct 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Michael Drumheller | last post by:
(If you're not interested in NumArray, please skip this message.) I am new to NumArray and I wonder if someone can help me with array-indexing. Here's the basic situation: Given a rank-2 array...
2
by: Dave Bazell | last post by:
I have a multidimensional array, say 20 x 6, and I want to take a subset of the rows. I have an index array @indx=(1,3,12,17) for example, and what I want to say is @new_array = $data I know...
4
by: Jim O'D | last post by:
Hi all I have an array a=array(). I want to extract an array with all the elements of a that are less than 0. Method 1. new = array() Method 2.
3
by: masood.iqbal | last post by:
Hi, I have seen at least two ways to initialize multi-dimensional arrays in C. One of the ways is shown in a sample code snippet below. The other way does not make use of any intermediate...
6
by: ad | last post by:
I have a huge sting array, there are about 1000 element in it. How can I divide the huge array into small ones, and there are one 10 elements in a small one array?
3
by: Nathan Sokalski | last post by:
I have an array declared as follows: Dim ButtonList() As NavButtonInfo and a Class defined as follows: Public Class NavButtonInfo Public Shared name As String
6
by: Denis C | last post by:
Hi I have a byte array of length 2404. I want to access subsets of the array and pass the subset to the constructor of a class. i.e. Dim bData(2403) As Byte Dim aThing As SomeClass = new...
7
by: Jacob JKW | last post by:
I need to iterate over combinations of n array elements taken r at a time. Because the value of r may vary quite a bit between program invocations, I'd like to avoid simply hardcoding r loops. I...
5
by: M. Fisher | last post by:
Pardon my ignorance here... I have created arrays such as: var SDET_Lab130= new Array(); SDET_Lab130 = new Array(); SDET_Lab130 = ; SDET_Lab130 = ; SDET_Lab130 = ; SDET_Lab130 = ;...
57
by: buuuuuum | last post by:
why array can't be assigned, like structs?
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.