{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\nWhat is PyTorch?\n================\n\nIt\u2019s a Python based scientific computing package targeted at two sets of\naudiences:\n\n- A replacement for numpy to use the power of GPUs\n- a deep learning research platform that provides maximum flexibility\n and speed\n\nGetting Started\n---------------\n\nTensors\n^^^^^^^\n\nTensors are similar to numpy\u2019s ndarrays, with the addition being that\nTensors can also be used on a GPU to accelerate computing.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from __future__ import print_function\nimport torch" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Construct a 5x3 matrix, uninitialized:\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "x = torch.Tensor(5, 3)\nprint(x)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Construct a randomly initialized matrix\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "x = torch.rand(5, 3)\nprint(x)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Get its size\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "print(x.size())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
``torch.Size`` is in fact a tuple, so it supports the same operations
Any operation that mutates a tensor in-place is post-fixed with an ``_``\n For example: ``x.copy_(y)``, ``x.t_()``, will change ``x``.