# What is .numpy()?

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.

That is part of TensorFlow's eager execution:

Tensors can be explicitly converted to NumPy ndarrays by invoking the .numpy() method on them.

There is no such thing as numpy.numpy(). There is no numpy function inside of the NumPy package. The numpy function is only in the TensorFlow package.

The NumPy package is frequently imported with alias:

import numpy as np

After importing the NumPy package, you have access to NumPy's modules and functions:

np.random.random_sample()`

• When I took the Udacity DLND course, eager execution was never even mentioned. "TensorFlow's eager execution is an imperative programming environment that evaluates operations immediately, without building graphs: operations return concrete values instead of constructing a computational graph to run later. This makes it easy to get started with TensorFlow and debug models, and it reduces boilerplate as well. To follow along with this guide, run the code samples below in an interactive python interpreter." from tensorflow.org/guide/eager May 6 '19 at 6:17