Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6553503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:35:22+00:00 2026-05-25T12:35:22+00:00

I have two 2D numpy arrays – real r , which contains points in

  • 0

I have two 2D numpy arrays – real r, which contains points in space, given by their Cartesian coordinates, and v, a complex vector defined at each of these points. I would like to split both of these arrays, based on some condition on r.

e.g., r1 contains all points with the first cartesian coordinate is positive, and v1 gives the corresponding values of v. All other points and their corresponding vectors go into .

Based on this question, and the fact that zip is essentially it’s own inverse, I currently have the following solution:

r1, v1 = zip(*[rv for rv in zip(r, v) if rv[0][0] > 0.0])
r2, v2 = zip(*[rv for rv in zip(r, v) if rv[0][0] <= 0.0])
r1 = np.array(r1)
r2 = np.array(r2)
v1 = np.array(v1)
v2 = np.array(v2)

This works well enough for my purposes, however it involves conversion to large lists of arrays, which is surely quite inefficient.

Is there an alternative solution, which is fast, concise and avoids the creation of intermediate lists?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T12:35:23+00:00Added an answer on May 25, 2026 at 12:35 pm

    you can use bool array as index to filter out values:

    create some random test data first:

    import numpy as np
    np.random.seed(0)
    r = np.random.rand(10,2)-0.5
    v = np.random.rand(10) + np.random.rand(10)*1j
    

    then:

    idx = r[:,0] > 0 # idx is a bool array 
    r1 = r[idx]
    v1 = v[idx]
    
    r2 = r[~idx] # ~idx compute bit-wise NOT, element-wise
    v2 = v[~idx]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'v got two numpy arrays. The first array contains some zeros (which are distributed
I have two identically-sized numpy.array objects (both one-dimensional), one of which contains a list
I have two arrays, the first one is a (n, 2) array which contains
I have two arrays of System.Data.DataRow objects which I want to compare. The rows
Suppose that I have two numpy arrays of the form x = [[1,2] [2,4]
I have two arrays of x - y coordinates, and I would like to
I have two Numpy record arrays that have exactly the same fields. What is
I have two equal-length 1D numpy arrays, id and data , where id is
I have two equally sized numpy arrays (they happen to be 48x365) where every
I have two numpy arrays of different shapes, but with the same length (leading

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.