How to do it...

We will first look at one-dimensional data. We need to generate a random array of data for this task using the following steps:

  1. We'll start by loading the libraries we need and starting a graph session, as follows:
import tensorflow as tf 
import numpy as np 
sess = tf.Session() 
  1. Now we can initialize our data (a NumPy array of length 25) and create the placeholder that we will feed it through with the following code:
data_size = 25 
data_1d = np.random.normal(size=data_size) 
x_input_1d = tf.placeholder(dtype=tf.float32, shape=[data_size])
  1. Next, we will define a function that will make a convolutional layer. Then we will declare a random filter and create the convolutional layer, as follows:
Note that many of TensorFlow's ...

Get TensorFlow Machine Learning Cookbook - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.