Master LLMs with our FREE course in collaboration with Activeloop & Intel Disruptor Initiative. Join now!

Publication

Visual Representation of Matrix and Vector Operations and implementation in NumPy, Torch, and Tensor
Deep Learning

Visual Representation of Matrix and Vector Operations and implementation in NumPy, Torch, and Tensor

Last Updated on January 6, 2023 by Editorial Team

Author(s): Balakrishnakumar V

Deep Learning

Visual Representation of Matrix and Vector Operations and implementations in NumPy, Torch, and TensorFlow.

Implementing rudimentary to advanced operations on deep learning’s fundamental units.

Excerpts

I am accustomed to creating new deep learning architectures for different problems, but which framework (Keras, Pytorch, TensorFlow) to choose is often harder.

Since there’s an uncertainty in it, it’s good to know the fundamental operations on those framework’s fundamental units (NumPy, Torch, Tensor).

In this post, I have performed a handful of the same operations across the 3 frameworks, also tried my hands on visualization for most of them.

This is a beginner-friendly post, so let’s get started.

1. Installation

2. Version Check

3. Array Initialization ~ 1-D, 2-D, 3-D

Scalar and 1-D Array

Scalar, 1-D, 2-D arrays

Numpy Implementation:

TensorFlow Implementation:

Torch Implementation:

2-D Vector Array

2-D Array

Numpy Implementation:

TensorFlow Implementation:

Torch Implementation:

4. Generating Data

Zeros and Ones
Diagonal & Same element fill

Numpy Implementation:

TensorFlow Implementation:

Torch Implementation:

Draw random samples from the Normal distribution

Normal Dist’n Bell Curve
Samples were drawn from Normal Dist’n

Numpy Implementation:

TensorFlow Implementation:

Torch Implementation:

Draw samples from the uniform distribution

Uniform Dist’n Curve
Samples were drawn from Uniform Dist’n

Numpy Implementation:

TensorFlow Implementation:

Torch Implementation:

6. Vector Arrangements

Numpy Implementation:

TensorFlow Implementation:

Torch Implementation:

7. Data-Type — Conversions

uint8/16/32/64 ← → float8/16/32/64

Numpy Implementation:

TensorFlow Implementation:

Torch Implementation:

8. Math Operations

Sum and Subtract operations
multiply and divide operations

Numpy Implementation:

TensorFlow Implementation:

Torch Implementation:

9. Dot Product

Dot Product

Numpy Implementation:

TensorFlow Implementation:

Torch Implementation:

10. Matrix Multiplication

Matrix Multiplication

Numpy Implementation:

TensorFlow Implementation:

Torch Implementation:

11. Indexing and Slicing (2-D)

Indexing and Slicing

Numpy Implementation:

TensorFlow Implementation:

Torch Implementation:

12. Indexing and Slicing (2-D — Matrix)

Matrix Slicing

Numpy Implementation:

TensorFlow Implementation:

Torch Implementation:

13. Reshaping and Transpose axes

Reshape & Transpose

Numpy Implementation:

TensorFlow Implementation:

Torch Implementation:

14. Concatenation

Matrix Concatenation

Numpy Implementation:

TensorFlow Implementation:

Torch Implementation:

15. Summing across axes

Axes — Sum

Numpy Implementation:

TensorFlow Implementation:

Torch Implementation:

16. Mean across axes

Numpy Implementation:

TensorFlow Implementation:

Torch Implementation:

17. Dimension Expansion & moving axes.

Concat and move axes

Numpy Implementation:

TensorFlow Implementation:

Torch Implementation:

18. Max (Min) and Argmax :

Max for axis=0
Max for axis=1

Numpy Implementation:

TensorFlow Implementation:

Torch Implementation:

19. Slicing and Indexing (3-D Matrix)

3×3 Matrix and its indices
Upper-Left & Lower-Right
Middle Elements & Inverse Middle Element

Numpy Implementation:

TensorFlow Implementation:

Torch Implementation:

Due to visualization constraints, I skipped the operations on the higher dimension parts.

I hope I was able to provide some visual understanding to some of the fundamental operations along with your choice of deep learning framework and I will add more detailed operations shortly.

Check out the Notebook to find the above codes curated here → Colab.

Until then, see you next time.

Article By:

BALAKRISHNAKUMAR V

Co-Founder — DeepScopy (An AI-Based Medical Imaging Startup)

Connect with meLinkedIn, GitHub, TwitterMedium

https://deepscopy.com/

`

Visit us DeepScopy

Connect with usTwitter, LinkedIn, Medium


Visual Representation of Matrix and Vector Operations and implementation in NumPy, Torch, and Tensor was originally published in Towards AI — Multidisciplinary Science Journal on Medium, where people are continuing the conversation by highlighting and responding to this story.

Published via Towards AI

Feedback ↓