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 3429250
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T07:03:32+00:00 2026-05-18T07:03:32+00:00

I have a recarray with a couple columns that I use for selecting a

  • 0

I have a recarray with a couple columns that I use for selecting a subset. Something like

>>> x
   array([ ('label1',True,3),
          ('label2',True,2),
          ('label1',False,4)],
         dtype=[('status', '|S16'), ('select', '|b1'), ('somedata', '<i4')])

Data is selected from this array using an approach similar to a previous SO question.

condit=(x['status']=='label1')&(x['select']==True)
x_subids=numpy.where(condit)[0]
x_sub=x[x_subids]

Then I do some work on the subset and update the original.

x[x_subids]=x_sub

I understand that x_sub is a copy rather than a view due to advanced indexing, and I was wondering if there was an elegant way of avoiding the array copy and just working with the original given the conditions that I need to subset the data.

  • 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-18T07:03:32+00:00Added an answer on May 18, 2026 at 7:03 am

    The kind of modifications you mention in the comments to my first answer can be done with the numpy.place() function:

    >>> import numpy
    >>> x = numpy.array([("label1",True,3), ("label2",False,2), ("label1",True,4)],
    ...     dtype=[("status", "|S16"), ("select", "|b1"), ("somedata", ">> mask = x["select"]
    >>> numpy.place(x["somedata"], mask, (5, 6))
    >>> print x
    [('label1', True, 5) ('label2', False, 2) ('label1', True, 6)]
    >>> numpy.place(x["status"], mask, "label3")
    >>> print x
    [('label3', True, 5) ('label2', False, 2) ('label3', True, 6)]
    

    Note that

    1. I changed the values and conditions a bit for the sake of a pertinent example.

    2. This time, the values where mask is True are selected again, not masked out as in my previous answer.

    3. The ==True part in your mask condit is redundant, just leave it out 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple question about how to use multiple indicies for an array
Have an app that can use tts to read text messages. It can also
I have a Numpy rec array from which I would like to do some
Suppose I have a recarray such as the following: import numpy as np #
Have 2 tables for example: In 1st: object & parent columns object | parent
The problem I have an array of java.awt.Rectangle s. For those who are not
**Have it working now. I forgot to populate the Array List. How embarrassing. I'm
Have a bunch of WCF REST services hosted on Azure that access a SQL
I have few arrays of ccspirit images, these are balloons of different colors, like
have been trying couple of hours now to make my iphone app universal. The

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.