I searched for numpy.numpy()
and tried replacing .numpy()
with .np()
because numpy is already imported as np
here: Tensorflow tutorial
But using `.np() returns an error.
In the section, "Creating training examples and targets" there is:
# Create training examples / targets
char_dataset = tf.data.Dataset.from_tensor_slices(text_as_int) #slices text_as_int into elements for dataset
print(type(char_dataset))
for i in char_dataset.take(5): #from 0 to 4
print(i, i.numpy())
print(idx2char[i.numpy()])
That outputs:
<class 'tensorflow.python.data.ops.dataset_ops.TensorSliceDataset'>
tf.Tensor(18, shape=(), dtype=int64) 18
F
tf.Tensor(47, shape=(), dtype=int64) 47
i
tf.Tensor(56, shape=(), dtype=int64) 56
r
tf.Tensor(57, shape=(), dtype=int64) 57
s
tf.Tensor(58, shape=(), dtype=int64) 58
t
So i
is a tensor and .numpy()
seems to convert that into the int
representing the character in the text. However, I was looking for a more formal explanation.