8000 Testing Single-element NumPy Array Against Empty Python List · Issue #6722 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content
Testing Single-element NumPy Array Against Empty Python List #6722
Closed
@cgshep

Description

@cgshep

When I test a single-element NumPy array against a regular Python list, np.array([1]) != [], the result evaluates to neither true nor false, while one of multiple elements evaluates to true. E.g. 'boo' is printed with the following:

a = np.array([1])
b = np.array([1,2])

if a != []:
    print("foo")

if a == []:
    print("moo")

if b != []:
    print("boo")

Using the interpreter:

>>> import numpy as np
>>> a = np.array([1])
>>> b = np.array([1,2])
>>> a != []
array([], dtype=bool)
>>> a == []
array([], dtype=bool)
>>> b == []
False

This seems strange. Was this intended?

Tested with Python 2.7.10 and 3.4.2, using Numpy 1.10.1.
Linux 4.2.6-200.fc22.x86_64 (Fedora 22)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0