Sep-17-2018, 01:09 PM
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
Test everything in a Python shell (iPython, Azure Notebook, etc.)
- Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
- Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
- You posted a claim that something you did not test works? Be prepared to eat your hat.