Numpy where syntax from docs

后端 未结 3 1605
我寻月下人不归
我寻月下人不归 2020-12-12 04:44

Trying to teach myself some python and I am super confused from the docs what the where function does. Can somebody explain the example from the documentation below step by

3条回答
  •  隐瞒了意图╮
    2020-12-12 05:39

    Basically used as follows:

    np.where(condition, value if condition is True, value if condition is False)
    

    In this case:

    condition is [[True, False], [True, True]]

    value if condition is True is [[1, 2], [3, 4]].

    value if condition is False is [[9, 8], [7, 6]].

    The final result of array([[1, 8], [3, 4]]) is equal to the array from 'value if condition is True', except for the one location in condition where it is False. In this case, the value of 8 comes from the second array.

提交回复
热议问题