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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:57:20+00:00 2026-06-09T18:57:20+00:00

I am using numpy. I have one array Y and one matrix X .

  • 0

I am using numpy.

I have one array Y and one matrix X. This is for a regression. They arrays has labels, e.g. 0,1,2,3,4,5. I need to create a new array that has label 0 removed for all rows and the corresponding row in X removed as well. What is the most efficient means to do this?

e.g.

for i in xrange(y.shape):
    if y==0:
       pop y pop X
  • 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-06-09T18:57:22+00:00Added an answer on June 9, 2026 at 6:57 pm

    Numpy arrays are not good at appending/removing rows. If you know which rows are to be deleted, just extract the other rows (you need) and create a new array.

    I don’t understand your question very well, so please correct me if I am wrong:

    x = x[y != 0]
    y = y[y != 0]
    

    Example:

    import numpy as np
    x = np.array([[11, 12, 13], [21, 22, 23], [31, 32, 33]])
    y = np.array([1, 0, 3])
    x = x[y != 0]
    y = y[y != 0]
    

    now:

    x == array([[11, 12, 13],
                [31, 32, 33]])
    y == array([1, 3])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Numpy and have a 7x12x12 matrix whose values I would like to
I have an numpy array which I save to a image using savefig(). Then
I'm using numpy to create a cube array with sides of length 100, thus
I am new to using numpy and one thing that I really don't understand
If I have a list of numpy arrays, then using remove method returns a
I have a 2D numpy array. Some of the values in this array are
I have a very large matrix(10x55678) in numpy matrix format. the rows of this
I have a numpy one dimensional array c that is supposed to be filled
I have an array like this numpy array dd= [[foo 0.567 0.611] [bar 0.469
I have some board numpy arrays like that: array([[0, 0, 0, 1, 0, 0,

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.