Skip to Content
Python Machine Learning, Second Edition - Second Edition
book

Python Machine Learning, Second Edition - Second Edition

by Sebastian Raschka, Jared Huffman, Vahid Mirjalili, Ryan Sun
September 2017
Intermediate to advanced content levelIntermediate to advanced
622 pages
15h 13m
English
Packt Publishing
Content preview from Python Machine Learning, Second Edition - Second Edition

Transforming Tensors as multidimensional data arrays

In this section, we explore a selection of operators that can be used to transform tensors. Note that some of these operators work very similar to NumPy array transformations. However, when we are dealing with tensors with ranks higher than 2, we need to be careful in using such transformations, for example, the transpose of a tensor.

First, as in NumPy, we can use the attribute arr.shape to get the shape of a NumPy array. In TensorFlow, we use the tf.get_shape function instead:

>>> import tensorflow as tf >>> import numpy as np >>> >>> g = tf.Graph() >>> with g.as_default(): ... arr = np.array([[1., 2., 3., 3.5], ... [4., 5., 6., 6.5], ... [7., 8., 9., 9.5]]) ... T1 = tf.constant(arr, name='T1') ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Python Machine Learning - Third Edition

Python Machine Learning - Third Edition

Sebastian Raschka, Vahid Mirjalili
Python Machine Learning

Python Machine Learning

Sebastian Raschka

Publisher Resources

ISBN: 9781787125933Supplemental Content