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 675147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:47:10+00:00 2026-05-14T00:47:10+00:00

The numpy.equal function does not work if a list or array contains strings: >>>

  • 0

The numpy.equal function does not work if a list or array contains strings:

>>> import numpy
>>> index = numpy.equal([1,2,'a'],None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: function not supported for these types, and can't coerce safely to supported types

What is the easiest way to workaround this without looping through each element? In the end, I need index to contain a boolean array indicating which elements are None.

  • 1 1 Answer
  • 1 View
  • 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-05-14T00:47:10+00:00Added an answer on May 14, 2026 at 12:47 am

    If you really need to use numpy, be more careful about what you pass in and it can work:

    >>> import numpy
    >>> a = numpy.array([1, 2, 'a'], dtype=object) # makes type of array what you need
    >>> numpy.equal(a, None)
    array([False, False, False], dtype=bool)
    

    Since you start with a list, there’s a chance what you really want is just a list comprehension like [item is None for item in [1, 2, 'a']] or the similar generator expression.

    To have an a heterogeneous list like this is odd. Lists (and numpy arrays) are typically used for homogeneous data.

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

Sidebar

Related Questions

In the following example In [8]: import numpy as np In [9]: strings =
I'm using a numpy object_ array to store variable length strings, e.g. a =
I'v got two numpy arrays. The first array contains some zeros (which are distributed
import numpy as np x = np.array(range(10 * 30)).reshape(100, 3) y = np.array(range(1010, 10,
In Numpy (and Python in general, I suppose), how does one store a slice-index,
I have a numpy array of strings. When a value in the array is
I'm creating a numpy array which is to be filled with objects of a
I have a NumPy array [1,2,3,4,5,6,7,8,9,10,11,12,13,14] and want to have an array structured like
I have a numpy array with positive and negative values in. a = array([1,1,-1,-2,-3,4,5])
How can I build a numpy array out of a generator object? Let me

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.