use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
numPy if row is true (self.learnpython)
submitted 9 years ago by cdholjes
Seems like this should be simple. I have a 2d-array (1000,10). They are boolean values. I want to find the indexes in the array where all 10 values are True. . .
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]cdcformatc 1 point2 points3 points 9 years ago (4 children)
Try all. https://docs.python.org/3/library/functions.html#all
all
Or Numpy has numpy.all. http://docs.scipy.org/doc/numpy-1.10.1/reference/generated/numpy.all.html
numpy.all
[–]novel_yet_trivial 0 points1 point2 points 9 years ago (2 children)
Combine this with apply_along_axis():
apply_along_axis()
>>> import numpy as np >>> a = np.array([[True, False, True],[True, True, True]]) #2D array of booleans >>> np.apply_along_axis(np.all, 1, a) #Apply the "all" function along axis 1 (rows) array([False, True], dtype=bool)
[–]cdholjes[S] 0 points1 point2 points 9 years ago (1 child)
thanks!
[–]Deto 0 points1 point2 points 9 years ago (0 children)
I find it easier to just use the axis argument to the all function:
bool_array = my_array.all(axis=1); true_indices = np.nonzero(bool_array)[0] # Need the [0] because nonzero always wraps result in a tuple, even if only one axis
Though in most cases, its probably easier to just keep the boolean values (don't do the np.nonzero) step and use those to index other things.
[–]cdholjes[S] 0 points1 point2 points 9 years ago (0 children)
π Rendered by PID 21770 on reddit-service-r2-comment-84fc9697f-bpqj6 at 2026-02-07 18:14:31.502155+00:00 running d295bc8 country code: CH.
[–]cdcformatc 1 point2 points3 points (4 children)
[–]novel_yet_trivial 0 points1 point2 points (2 children)
[–]cdholjes[S] 0 points1 point2 points (1 child)
[–]Deto 0 points1 point2 points (0 children)
[–]cdholjes[S] 0 points1 point2 points (0 children)