diff --git a/Chapter 3/7. Quick Primer on Numpy.ipynb b/Chapter 3/7. Quick Primer on Numpy.ipynb index e2411e6..44e6587 100644 --- a/Chapter 3/7. Quick Primer on Numpy.ipynb +++ b/Chapter 3/7. Quick Primer on Numpy.ipynb @@ -270,6 +270,125 @@ "# Regardless of wheth- er you're \"dotting\" vectors or matrices. eir \"shape\"(number of rows and columns) must line up. \n", "#The col-umns on the \"le \" matrix must equal rows on the \"right\"." ] + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(2, 3)\n" + ] + } + ], + "source": [ + "a=np.zeros((2,4))\n", + "b=np.zeros((4,3))\n", + "\n", + "c=a.dot(b)\n", + "\n", + "print c.shape" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(2, 3)\n" + ] + } + ], + "source": [ + "e=np.zeros((2,1))\n", + "f=np.zeros((1,3))\n", + "\n", + "g=e.dot(f)\n", + "print g.shape" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[ 0. 0. 0. 0. 0.]\n", + " [ 0. 0. 0. 0. 0.]\n", + " [ 0. 0. 0. 0. 0.]\n", + " [ 0. 0. 0. 0. 0.]]\n" + ] + } + ], + "source": [ + "h=np.zeros((5,4)).T\n", + "print h" + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(4, 6)\n" + ] + } + ], + "source": [ + "i=np.zeros((5,6))\n", + "j=h.dot(i)\n", + "\n", + "print j.shape" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "metadata": {}, + "outputs": [ + { + "ename": "ValueError", + "evalue": "shapes (5,4) and (5,6) not aligned: 4 (dim 1) != 5 (dim 0)", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0mi\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mzeros\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m5\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m6\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 4\u001b[0;31m \u001b[0mj\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mh\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdot\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 5\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[0;32mprint\u001b[0m \u001b[0mj\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mshape\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mValueError\u001b[0m: shapes (5,4) and (5,6) not aligned: 4 (dim 1) != 5 (dim 0)" + ] + } + ], + "source": [ + "h=np.zeros((5,4))\n", + "i=np.zeros((5,6))\n", + "\n", + "j=h.dot(i)\n", + "\n", + "print j.shape" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] } ], "metadata": {