Skip to content

Commit

Permalink
Quick Primer on Numpy
Browse files Browse the repository at this point in the history
Quick Primer on Numpy
  • Loading branch information
Alluxia-F committed Jul 6, 2017
1 parent 444e44a commit 6fc99dc
Showing 1 changed file with 119 additions and 0 deletions.
119 changes: 119 additions & 0 deletions Chapter 3/7. Quick Primer on Numpy.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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<ipython-input-45-74e2469b12b9>\u001b[0m in \u001b[0;36m<module>\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": {
Expand Down

0 comments on commit 6fc99dc

Please sign in to comment.