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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:21:13+00:00 2026-06-18T05:21:13+00:00

I have a numpy ndarray that I made using numpy.loadtxt. I want to pull

  • 0

I have a numpy ndarray that I made using numpy.loadtxt. I want to pull an entire row from it based on a condition in the third column. Something like : if array[2][i] is meeting my conditions, then get array[0][i] and array [1][i] as well. I’m new to python, and all of the numpy features, so I’m looking for the best way to do this. Ideally, I’d like to pull 2 rows at a time, but I wont always have an even number of rows, so I imagine that is a problem

import numpy as np

'''
Created on Jan 27, 2013

@author:
'''
class Volume:

    f ='/Users/Documents/workspace/findMinMax/crapc.txt'
    m = np.loadtxt(f, unpack=True, usecols=(1,2,3), ndmin = 2)


    maxZ = max(m[2])
    minZ = min(m[2])
    print("Maximum Z value: " + str(maxZ))
    print("Minimum Z value: " + str(minZ))

    zIncrement = .5
    steps = maxZ/zIncrement
    currentStep = .5
    b = []

    for i in m[2]:#here is my problem
         while currentStep < steps: 
            if m[2][i] < currentStep and m[2][i] > currentStep - zIncrement:
                b.append(m[2][i]) 
            if len(b) < 2:
                currentStep + zIncrement

                print(b)

Here is some code that I did in java that is the general idea of what I want:

while( e < a.length - 1){
for(int i = 0; i < a.length - 1; i++){
        if(a[i][2] < stepSize && a[i][2] > stepSize - 2){

            x.add(a[i][0]);
            y.add(a[i][1]);
            z.add(a[i][2]);
        }
        if(x.size()  < 1){
            stepSize += 1;
        }
    }
}
  • 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-18T05:21:15+00:00Added an answer on June 18, 2026 at 5:21 am

    First of all, you probably don’t want to put your code in that class definition…

    import numpy as np
    
    
    def main():
        m = np.random.random((3, 4))
        mask = (m[2] > 0.5) & (m[2] < 0.8)  # put your conditions here
                                            # instead of 0.5 and 0.8 you can use
                                            # an array if you like
        m[:, mask]
    
    if __name__ == '__main__':
        main()
    

    mask is a boolean array, m[:, mask] is the array you want

    m[2] is the third row of m. If you type m[2] + 2 you get a new array with the old values + 2. m[2] > 0.5 creates an array with boolean values. It is best to try this stuff out with ipython (www.ipython.org)

    In the expression m[:, mask] the : means “take all rows”, mask describes which columns should be included.

    Update

    Next try 🙂

    for i in range(0, len(m), 2):
        two_rows = m[i:i+2]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an object from a library (numpy.ndarray), in which I've substituted the _
I have a one-dimensional array of the type numpy.ndarray and I want to know
If I have an 1D numpy.ndarray b and a Python function f that I
I have two numpy.ndarray and i found a not elegant solution (using more than
I have an object of type 'numpy.ndarray', called myarray, that when printed to the
I have a numpy ndarray that looks something like: [[0, 0.25, 1, ...., 0.5,
I have two numpy arrays that are OpenCV convex hulls and I want to
Are there any C++ (or C) libs that have NumPy-like arrays with support for
I have an numpy array which I save to a image using savefig(). Then
I have two numpy arrays that define the x and y axes of a

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.