Learn practical skills, build real-world projects, and advance your career
!pip install jovian --upgrade --quiet

In this notebook, we are going to learn about PyTorch Tensors.

What is a Tensor?

A Tensor can simply be a scalar(number) or a generic n-dimensional vector, matrix or an array which is similar to a numpy array. Tensors can be put on GPU where as the numpy arrays exist only on CPU.

A Tensor consists of single data type.

Let's begin installing and importing necessary libraries
!conda install pytorch cpuonly -c pytorch -y
Collecting package metadata (current_repodata.json): done Solving environment: done ==> WARNING: A newer version of conda exists. <== current version: 4.8.2 latest version: 4.8.3 Please update conda by running $ conda update -n base conda ## Package Plan ## environment location: /srv/conda/envs/notebook added / updated specs: - cpuonly - pytorch The following packages will be downloaded: package | build ---------------------------|----------------- blas-1.0 | mkl 6 KB defaults ca-certificates-2020.6.20 | hecda079_0 145 KB conda-forge certifi-2020.6.20 | py37hc8dfbb8_0 151 KB conda-forge cpuonly-1.0 | 0 2 KB pytorch intel-openmp-2019.4 | 243 729 KB defaults libgfortran-ng-7.5.0 | hdf63c60_6 1.7 MB conda-forge mkl-2019.4 | 243 131.2 MB defaults mkl-service-2.3.0 | py37h516909a_0 64 KB conda-forge mkl_fft-1.1.0 | py37hc1659b7_1 173 KB conda-forge mkl_random-1.1.0 | py37hd6b4f25_0 321 KB defaults ninja-1.10.0 | hc9558a2_0 1.9 MB conda-forge numpy-1.18.5 | py37ha1c710e_0 5 KB defaults numpy-base-1.18.5 | py37hde5b4d6_0 4.1 MB defaults pytorch-1.5.1 | py3.7_cpu_0 37.9 MB pytorch ------------------------------------------------------------ Total: 178.3 MB The following NEW packages will be INSTALLED: blas pkgs/main/linux-64::blas-1.0-mkl cpuonly pytorch/noarch::cpuonly-1.0-0 intel-openmp pkgs/main/linux-64::intel-openmp-2019.4-243 libgfortran-ng conda-forge/linux-64::libgfortran-ng-7.5.0-hdf63c60_6 mkl pkgs/main/linux-64::mkl-2019.4-243 mkl-service conda-forge/linux-64::mkl-service-2.3.0-py37h516909a_0 mkl_fft conda-forge/linux-64::mkl_fft-1.1.0-py37hc1659b7_1 mkl_random pkgs/main/linux-64::mkl_random-1.1.0-py37hd6b4f25_0 ninja conda-forge/linux-64::ninja-1.10.0-hc9558a2_0 numpy pkgs/main/linux-64::numpy-1.18.5-py37ha1c710e_0 numpy-base pkgs/main/linux-64::numpy-base-1.18.5-py37hde5b4d6_0 pytorch pytorch/linux-64::pytorch-1.5.1-py3.7_cpu_0 The following packages will be UPDATED: ca-certificates 2020.4.5.1-hecc5488_0 --> 2020.6.20-hecda079_0 certifi 2020.4.5.1-py37hc8dfbb8_0 --> 2020.6.20-py37hc8dfbb8_0 Downloading and Extracting Packages mkl-2019.4 | 131.2 MB | ##################################### | 100% intel-openmp-2019.4 | 729 KB | ##################################### | 100% pytorch-1.5.1 | 37.9 MB | ##################################### | 100% mkl-service-2.3.0 | 64 KB | ##################################### | 100% libgfortran-ng-7.5.0 | 1.7 MB | ##################################### | 100% mkl_fft-1.1.0 | 173 KB | ##################################### | 100% mkl_random-1.1.0 | 321 KB | ##################################### | 100% numpy-base-1.18.5 | 4.1 MB | ##################################### | 100% ninja-1.10.0 | 1.9 MB | ##################################### | 100% certifi-2020.6.20 | 151 KB | ##################################### | 100% numpy-1.18.5 | 5 KB | ##################################### | 100% ca-certificates-2020 | 145 KB | ##################################### | 100% cpuonly-1.0 | 2 KB | ##################################### | 100% blas-1.0 | 6 KB | ##################################### | 100% Preparing transaction: done Verifying transaction: done Executing transaction: done