数据操作

https://zh-v2.d2l.ai/chapter_preliminaries/ndarray.html

Can someone explain the result of excersice 1?

as the same of X == Y

TensorFlow中的Tensors可以使用这个tf.tensor_scatter_nd_update函数更新, 并不是不可变的吧, 只是更新比较麻烦

excersice 1:
X > Y:
<tf.Tensor: shape=(3, 4), dtype=bool, numpy=
array([[False, False, False, False],
[ True, True, True, True],
[ True, True, True, True]])>

X < Y:
<tf.Tensor: shape=(3, 4), dtype=bool, numpy=
array([[ True, False, True, False],
[False, False, False, False],
[False, False, False, False]])>

excersice 2:
input:
c = tf.reshape(tf.range(3), (3, 1, 1))
d = tf.reshape(tf.range(2), (1, 2, 1))
c, d

c+d

output:
(<tf.Tensor: shape=(3, 1, 1), dtype=int32, numpy=
array([[[0]],

    [[1]],

    [[2]]])>,

<tf.Tensor: shape=(1, 2, 1), dtype=int32, numpy=
array([[[0],
[1]]])>)

<tf.Tensor: shape=(3, 2, 1), dtype=int32, numpy=
array([[[0],
[1]],

   [[1],
    [2]],

   [[2],
    [3]]])>

So the tensor will broadcast to the same shape (3, 2, 1) and then add by element.The same as expected.

If you get different output in exercise 1, check the value of Y because it has been changed by the later command in this book.