Let me ask (possibly) a very basic question.
See the code below.
import tensorflow as tf
i = tf.range(3)[:, tf.newaxis]
j = tf.range(3)
tf.cast(i>=j, dtype="int32")
When I run this code, I get the below.
I mean a lower triangular 3x3 matrix(tensor).
<tf.Tensor: shape=(3, 3), dtype=int32, numpy=
array([[1, 0, 0],
[1, 1, 0],
[1, 1, 1]], dtype=int32)>
What I want to know is
-
How tf.newaxis works in
i = tf.range(3)[:, tf.newaxis]
As far as I understand,i
is basicly a column vector but to make it a matrix, it makes a room for more columns.
Is this right? -
In the code above, I didn’t make a 3x3 matrix anywhere but finally I get a 3x3 matrix.
tf.cast is originally a function to convert a type from one to another, not a function to make a matrix.
But actually I get a matrix.
Why?