Using Nx Operations
Now that you have a better understanding of what a tensor is, it’s time to get a better understanding of how to manipulate tensors.
Nx comes with a number of operations you can use and compose into complex mathematical operations and algorithms. There are four common types of operations you should get comfortable with first: shape and type operations, element-wise unary operations, element-wise binary operations, and reductions.
Shape and Type Operations
Shape and type operations work on the shape and type properties of a tensor. Run the following code in a Livebook cell to create a new tensor with shape {3} and type {:s, 64}:
| a = Nx.tensor([1, 2, 3]) |
Then, run the following code to cast the tensor to type {:f, 32} and change ...
Get Machine Learning in Elixir now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.