たとえば、これらの結果を理解しようとすると、次のようになります。
>>> x
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
>>> (x == np.array([[1],[2]])).astype(np.float32)
array([[ 0., 1., 0., 0., 0., 0., 0., 0., 0., 0.],
[ 0., 0., 1., 0., 0., 0., 0., 0., 0., 0.]], dtype=float32)
>>> (x == np.array([1,2]))
False
>>> (x == np.array([[1]])).astype(np.float32)
array([[ 0., 1., 0., 0., 0., 0., 0., 0., 0., 0.]], dtype=float32)
>>> (x == np.array([1])).astype(np.float32)
array([ 0., 1., 0., 0., 0., 0., 0., 0., 0., 0.], dtype=float32)
>>> (x == np.array([[1,3],[2]]))
False
>>>
何が起きてる?[1] の場合、1 を x の各要素と比較し、結果を配列に集計しています。[[1]]の場合も同様です。repl で実験するだけで、特定の配列形状で何が起こるかを簡単に把握できます。しかし、両側が任意の形状を持つことができる基本的なルールは何ですか?