Tensor and View

View uses the same data chunk from the original tensor, just a different way to ‘view’ its dimension.

Before we dive into the discussion about what does contiguous vs. non-contiguous mean, we need to first understand the relations between Tensor and View in Pytorch.

View is nothing but an alternative way to interpret the original tensor’s dimension without making a physical copy in the memory. For example, we can have a 1x12 tensor, i.e. [1,2,3,4,5,6,7,8,9,10,11,12] and then use to change the shape of the tensor into a 4x3 structure.

x = torch.arange(1,13) print(x) >> tensor([ 1, 2, 3, 4…


Have you ever felt confused about how the tensor dimension works, especially when you need to apply operations like over high dimension? The technique you learn in this post not only works for tensor dimension, but also works for Numpy ndarray dimension, because the logic of multi-dimensional array/tensor are the same.

This post is going to solve the puzzle in your head once and for good. It will provide you:

  • An intuitive way to visualize how the operation works on tensor dimension.
  • An example using Pytorch to examine the tensor sum in code.

Shape (dimension) of the tensor

First, tensor is just another…


Striding is like taking steps with a given window size in the data. It is a very common technique which you will see in all kinds of data processing tasks. This tutorial will introduce the most basic concept of Stride, and how to use it in Numpy, and finally wrap up with a Pandas dataframe data processing use case.

In a nutshell, you will be introduced:

  1. What is stride?
  2. Data structure of a Numpy 2D array, in terms of its memory allocation
  3. How to stride on a Numpy array:
    “Usage of numpy.lib.stride_tricks.as_strided()”
  4. An useful use case in data processing: “How…


If you are a Python user, you must be familiar with Jupyter Notebook. The good news is Google has a cloud based service called CoLab. It is just like running Jupyter Notebook on Google Drive. No need to apply for additional accounts, and no need to apply for the service. All you need is a Google Drive account, and that’s it. Easy & Simple! The best thing is that it gives users free TPU access to run your task! …


I was struggling quite a bit while I started to use VSCode, because there is a lot of flexibility in VSCode, but it also implies that there is tons of detailed settings which allows all kinds of alternative usages. This post is going to introduce the head-to-toe process of how to use Conda environment in VSCode. The post would focus on Windows system, but the other OS users would find it useful too.

As the primary language I use is Python, I will use Python configuration in this demo, and let’s first look at two ways of running Python code…

Kathryn

Ontario Tech University

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store