Shape of numpy array comparison with empty list

ساخت وبلاگ

Vote count: 0

I have some problems understanding how python/numpy is casting array shapes when comparing to an empty list - which as far as I understand - is an implicit (element wise) comparison with False.

In the following example the shape decreases by one in the last dimension, if it is not greater than 1.

z = N.zeros((2,2,1))
z == []
>> array([], shape=(2, 2, 0), dtype=bool)
z2 = N.zeros((2,2,2))
z2 ==[]
>> False

If, however, I compare with False directly, I get the expected output.

z = N.zeros((2,2,1))
(z == False).shape
>> (2, 2, 2)
z2 = N.zeros((2,2,2))
(z2 == False).shape
>> (2, 2, 1)
asked 31 secs ago

back soft...
ما را در سایت back soft دنبال می کنید

برچسب : نویسنده : استخدام کار backsoft بازدید : 216 تاريخ : پنجشنبه 7 مرداد 1395 ساعت: 1:32