What are the dimensions of this array? [Python] [closed]

On example of code #1 at this link: <https://www.geeksforgeeks.org/numpy-where-in-python/

import numpy as np 

np.where([[True, False], [True, True]], 
        [[1, 2], [3, 4]], [[5, 6], [7, 8]])

What are its dimensions, and why? I’m trying to understand the output of the example:

array([[1, 6],
       [3, 4]])

Single brackets indicate 1-d lists, but there are pairs of these held together by a second square bracket so is that 2 rows and 2 columns x 6? Meaning two columns and 12 rows?

  • Have you tried using the shape function to determine the dimensions?

    – 

  • Dicover the doc of numpy.where at start

    – 




  • @FlyingTeller How do I get the shape of the initial array? If I wrap it in np.array() I get an error of three positional arguments when there should only be 2.

    – 

  • where is a python function, that takes 3 arguments. The resulting array is (2,2) shaped. Here the arguments are all nested lists, which when converted to arrays are also (2,2).

    – 




Leave a Comment