Python Forum
Checking the elements of a matrix with an elements of a list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Checking the elements of a matrix with an elements of a list
#11
(Sep-17-2018, 01:09 PM)volcano63 Wrote: Numpy arrays are intended to be used as objects - looping is wasteful and inefficient. This is how you can compare by rows and by columns
Output:
In [89]: table = numpy.array(range(1, 10)).reshape(3, 3) In [90]: table Out[90]: array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) In [91]: compare_to = numpy.array([2, 5, 6]) In [92]: compare_to Out[92]: array([2, 5, 6]) In [93]: # Compare by columns In [94]: table < compare_to Out[94]: array([[ True, True, True], [False, False, False], [False, False, False]]) In [95]: # Compare by rows In [96]: table < compare_to.reshape(3, 1) Out[96]: array([[ True, False, False], [ True, False, False], [False, False, False]])
numpy is a complex package - going into it without learning Python is a bad idea, and using it without learning is an exercise in futility

Hello , thank you so much
For an array [[1 2 3 ][ 4 5 6][7 8 9 ]] you used "numpy.array(range(1, 10))" If it was something like [[7 5 3][12 25 36][1 0 9]] how can I transform it ? Thank you
Reply
#12
I'm curious as to why you asked this question again.

https://python-forum.io/Thread-Selecting...3#pid58213
I am trying to help you, really, even if it doesn't always seem that way
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  OR-Tools LP Limit Number of Elements in Solution idratherbecoding 0 739 May-14-2023, 11:02 PM
Last Post: idratherbecoding
  Printing file path of lift elements dyerlee91 1 1,477 Sep-27-2021, 01:22 PM
Last Post: snippsat
  Join each list elements with string in other DF handy88 0 1,519 Feb-09-2021, 07:00 PM
Last Post: handy88
  updating cluster of elements based on the max value of distance alex80 0 1,573 Oct-02-2020, 11:11 AM
Last Post: alex80
  Fastest way to subtract elements of datasets of HDF5 file? Robotguy 3 2,585 Aug-01-2020, 11:48 PM
Last Post: scidam
  Formula with elements of list - If-condition regarding the lists elements lewielewis 2 2,702 May-08-2020, 01:41 PM
Last Post: nnk
  define certain array elements+display with digits lukezo 0 1,230 Apr-10-2020, 05:03 PM
Last Post: lukezo
  How to prepare a NumPy array which include float type array elements subhash 0 1,884 Mar-02-2020, 06:46 AM
Last Post: subhash
  How to access dataframe elements SriMekala 4 3,169 Jul-30-2019, 01:50 AM
Last Post: scidam
  When dividing elements of matrix i would like the result 0 instead of inf? Koczkodan 4 2,856 Jul-22-2019, 11:40 AM
Last Post: Koczkodan

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020