Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8821709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:55:25+00:00 2026-06-14T05:55:25+00:00

I need to find if a numpy array is inside other numpy array, but

  • 0

I need to find if a numpy array is inside other numpy array, but it seems to work different to python lists.
I tried to search this question in numpy documentation and internet, but not answer.
This is an example:


import numpy as np

m1=np.array([[1,2,3],[5,3,4]])
m2=np.array([5,4,3])
m2 in m1
True
m3=[[1,2,3],[5,3,4]]
m4=[5,4,3]
m4 in m3
False

In numpy I obtain True but with Python lists I obtain False. Is there any numpy function to make this work?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T05:55:26+00:00Added an answer on June 14, 2026 at 5:55 am

    To get the same behavior as in for lists, you could do something like this:

    any(np.all(row == m2) for row in m1)
    

    That does the loop over rows in python, which isn’t ideal, but it should work.

    To understand what’s going on with the numpy in, here’s a description of the semantics of in from Robert Kern on the numpy mailing list:

    It dates back to Numeric’s semantics for bool(some_array), which would
    be True if any of the elements were nonzero. Just like any other
    iterable container in Python, x in y will essentially do

    for row in y:
       if x == row:
           return True
    return False
    

    Iterate along the first axis of y and compare by boolean equality. In
    Numeric/numpy’s case, this comparison is broadcasted. So that’s why
    [3,6,4] works, because there is one row where 3 is in the first
    column. [4,2,345] doesn’t work because the 4 and the 2 are not in
    those columns.

    Probably, this should be considered a mistake during the transition to
    numpy’s semantics of having bool(some_array) raise an exception.
    scalar in array should probably work as-is for an ND array, but
    there are several different possible semantics for array in array
    that should be explicitly spelled out, much like bool(some_array).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to compute combinatorials (nCr) in Python but cannot find the function to
I need to convert a numpy array to a QtGui.QImage. But I don't know
I tried to find the eigenvalues of a matrix multiplied by its transpose but
I am new to python and numpy so please excuse me if this problem
I know there is a simple solution to this but can't seem to find
I'm writing a program in python and in it I need to find the
I have been searching for an answer to this question but cannot find anything
I know, maybe this question is stupid but I am stuck and I need
I need a fast way to keep a running maximum of a numpy array.
I need a python method to open and import TIFF images into numpy arrays

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.