Skip to content

how to use numpy.where in multi-conditions in python #5

Description

@LiNinghui-AI

I have met a issue. For example: I created the following array, and I want to use np.where for multiple condition judgments
import numpy as np
a = np.array( [1,2,3,4,5,6] )
b = np.array( [4,5,8,9,7,9])
I want to get a subscript that meets the conditions, but an error occurs
index = np.where(a >1 and b != 2 and a < 6)
The error is as follows:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
I don't want to use np.logical_and() , what is the solution? Thanks a lot!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions