0

I was wondering if there was some way in python to get rid of these extra brackets. example:

In [211]: a = np.array([1,3,4,6])

In [221]: np.where(a > 1)
Out[221]: (array([1, 2, 3]),)

In [222]: len(np.where(a > 1))
Out[222]: 1

In [223]: len(np.where(a > 1)[0])
Out[223]: 3
Coolcrab
  • 2,655
  • 9
  • 39
  • 59
  • Does this answer your question? [output of numpy.where(condition) is not an array, but a tuple of arrays: why?](https://stackoverflow.com/questions/33747908/output-of-numpy-wherecondition-is-not-an-array-but-a-tuple-of-arrays-why) – Mark Dickinson Oct 01 '20 at 19:49
  • `(foobar, )` is a one element tuple. `where` produces a tuple of arrays, one per dimension. – hpaulj Oct 01 '20 at 22:09
  • What is wrong with using `np.where(a > 1)[0]`? – Ehsan Oct 01 '20 at 23:44

0 Answers0