خرید بک لینک

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

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

صفحه بندی