Skip to content

Instantly share code, notes, and snippets.

@swwelch
Created March 20, 2015 01:53
Show Gist options
  • Save swwelch/f7db6f456f4f87db5653 to your computer and use it in GitHub Desktop.
Save swwelch/f7db6f456f4f87db5653 to your computer and use it in GitHub Desktop.
Linear Algebra with Numpy: Notation and Code
Display the source blob
Display the rendered blob
Raw
{
"metadata": {
"name": "",
"signature": "sha256:4d238a871fc72bca4938b16157f101b73b68b8e0c2e8e87ce994d89ed91198eb"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#Linear Algebra with Numpy: Notation and Code\n",
"\n",
"This document is intended to demonstrate basic linear algebra operations in Numpy.\n",
"\n",
"##Vectors\n",
"\n",
"A vector is a geometric object in Euclidean space that has magnitude and direction which is represented by an array of numbers. For the purpose of this document, we will represent vectors with Numpy arrays, and we will use vector/array interchangably. For example, here are three vectors:\n",
"\n",
"\\begin{aligned}\n",
" u &= [2, 7]\\\\\n",
" v &= [1, -3, 5, 3] \\\\\n",
" w &= [4, 67, -83, 2]\n",
"\\end{aligned}\n",
"\n",
"Now we can create the vectors above as arrays in Numpy and measure their length with the \"size\" property."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import numpy as np\n",
"u = np.array([2, 7])\n",
"print \"The length of u is: \" + str(u.size)\n",
"\n",
"v = np.array([1, -3, 5, 3])\n",
"print \"The length of v is: \" + str(v.size)\n",
"\n",
"w = np.array([4, 67, -83, 2])\n",
"print \"The length of w is: \" + str(w.size)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"The length of u is: 2\n",
"The length of v is: 4\n",
"The length of w is: 4\n"
]
}
],
"prompt_number": 14
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Another useful way to create vectors is to use Numpy's linspace function, which will return an array with evenly spaced numbers over a specified interval:"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"start_point = 5\n",
"end_point = 10\n",
"n_divisions = 40\n",
"l = np.linspace(start_point, end_point, n_divisions)\n",
"print l"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"[ 5. 5.12820513 5.25641026 5.38461538 5.51282051\n",
" 5.64102564 5.76923077 5.8974359 6.02564103 6.15384615\n",
" 6.28205128 6.41025641 6.53846154 6.66666667 6.79487179\n",
" 6.92307692 7.05128205 7.17948718 7.30769231 7.43589744\n",
" 7.56410256 7.69230769 7.82051282 7.94871795 8.07692308\n",
" 8.20512821 8.33333333 8.46153846 8.58974359 8.71794872\n",
" 8.84615385 8.97435897 9.1025641 9.23076923 9.35897436\n",
" 9.48717949 9.61538462 9.74358974 9.87179487 10. ]\n"
]
}
],
"prompt_number": 15
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Vectors Addition, Subtraction and Multiplication by Constants \n",
"\n",
"#### Algebraic definitions:\n",
"\n",
"Now that we have vectors in numpy, we can add them together and subtract them. Recall that vector addition and subtraction takes place component-wise, so vectors have to have the same length in order to be added or subtracted:\n",
"\n",
"\\begin{aligned}\n",
" v + w &= [1, -3, 5, 3] + [4, 67, -83, 2]\\\\ \n",
" &= [1 + 4, -3 + 67, 5 - 83, 3 + 2] = ?\\\\\n",
"\\end{aligned}\n",
"\n",
"\\begin{aligned}\n",
" v - w &= [1, -3, 5, 3] - [4, 67, -83, 2] \\\\\n",
" &= [1 - 4, -3 - 67, 5 + 83, 3 - 2] = ?\n",
"\\end{aligned}\n",
"\n",
"We can also multiply vectors by constants\n",
"\n",
"\\begin{aligned}\n",
" 5*v &= 5*[1, -3, 5, 3] \\\\\n",
" &= [5*1, 5*(-3), 5*5, 5*3]\n",
"\\end{aligned}\n",
"\n",
"We can do the computation above in Numpy:"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"print \"The vector v is: \" + str(v)\n",
"print \"The vector v is: \" + str(w) + \"\\n\"\n",
"print \"v + w:\"\n",
"print v + w\n",
"print \"v - w:\"\n",
"print v - w\n",
"print \"5v:\"\n",
"print 5*v"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"The vector v is: [ 1 -3 5 3]\n",
"The vector v is: [ 4 67 -83 2]\n",
"\n",
"v + w:\n",
"[ 5 64 -78 5]\n",
"v - w:\n",
"[ -3 -70 88 1]\n",
"5v:\n",
"[ 5 -15 25 15]\n"
]
}
],
"prompt_number": 16
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Note that if we try to add or subtract vectors that don't have the same length, we get an error:"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"print \"The vector v is: \" + str(v)\n",
"print \"The vector u is: \" + str(u)\n",
"u + v"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"The vector v is: [ 1 -3 5 3]\n",
"The vector u is: [2 7]\n"
]
},
{
"ename": "ValueError",
"evalue": "operands could not be broadcast together with shapes (2,) (4,) ",
"output_type": "pyerr",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-17-22fcbd7e6abc>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mprint\u001b[0m \u001b[0;34m\"The vector v is: \"\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mv\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0;32mprint\u001b[0m \u001b[0;34m\"The vector u is: \"\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mu\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0mu\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0mv\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;31mValueError\u001b[0m: operands could not be broadcast together with shapes (2,) (4,) "
]
}
],
"prompt_number": 17
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The error above tells us that we could not add two vectors with length 2 and length 4 respectively. Numpy refers to the dimension (rows, columns) as the \"shape\" of the object. Note that \"size\" refers to the product of dimensions. Here, our arrays have only a single dimension, so, only a single number for the shape, and the size refers to that number as well. Later we will show how to give the arrays another dimension so that we can think of them as row or column vectors. \n",
"\n",
"### Combining two vectors/arrays: Dot Product\n",
"\n",
"#### Algebraic Definition:\n",
"\n",
"There is common operation called the dot product which is used to combine two vectors of the same length together to get a single number back. To perform this operation we just multiply the numbers with the same indices in the two vectors together and add all the results together. So\n",
"\n",
"\\begin{equation}\n",
" w \\cdot v = 1 \\times 4 + (-3) \\times 67 + 5 \\times (-83) + 3 \\times 2 = \\,\\,?\n",
"\\end{equation}\n",
"\n",
"Note that is doesn't matter what order we put the vectors in the dot product; $w \\cdot v = v \\cdot w$. We could also compute the dot product by doing the arithmetic above manually, but there is a faster way using Numpy's .dot() function:\n"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"print np.dot(w, v)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"-606\n"
]
}
],
"prompt_number": 18
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"So, we see that $w \\cdot v = -606$. Great! We will see that np.dot() allows us to multiply matrices together as well later in the notebook.\n",
"\n",
"#### Geometric Interpretation:\n",
"\n",
"Since vectors are geometric objects with magnitude and direction, there is a geometric interpretation for the dot product as well. While this interpretation may not be as useful for understanding the mechanics of regression, it is definitely worthwhile to learn about. [Here is a link](http://en.wikipedia.org/wiki/Dot_product#Geometric_definition) where you can learn more.\n",
"\n",
"### Row and Column Vectors:\n",
"\n",
"It is also useful to be able to specify if a vector is a row vector or a column vector. To create a row vector, we just need to add an extra set of brackets when defining the array:"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"v = np.array([[1, -3, 5, 3]])\n",
"print \"The shape of v is: \" + str(v.shape)\n",
"\n",
"w = np.array([[4, 67, -83, 2]])\n",
"print \"The shape of w is: \" + str(w.shape)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"The shape of v is: (1, 4)\n",
"The shape of w is: (1, 4)\n"
]
}
],
"prompt_number": 19
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can turn one of the arrays above into column vectors by using Numpy's transpose feature, .T, which is an alias for np.transpose(). We can also check to see what happens with the dot product once we have done this:"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"w_t = w.T\n",
"print \"The shape of v is: \" + str(v.shape)\n",
"print \"The shape of w_t is: \" + str(w_t.shape)\n",
"print np.dot(v, w_t)\n",
"#Now we reverse the order\n",
"print np.dot(w_t, v)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"The shape of v is: (1, 4)\n",
"The shape of w_t is: (4, 1)\n",
"[[-606]]\n",
"[[ 4 -12 20 12]\n",
" [ 67 -201 335 201]\n",
" [ -83 249 -415 -249]\n",
" [ 2 -6 10 6]]\n"
]
}
],
"prompt_number": 20
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Note that the product $v w^t$ is a $(1,1)$ array in this case. Also, the product $w^t v$ is a $(4,4)$ array. Here, we view the row and column vectors as matrices; recall that for two matrices $A$ and $B$ with dimensions $(r_A, c_A)$ and $(r_B, c_B)$ respectively, in order to for the product $AB$, we must have $c_A = r_B$. The dimensions of the result will be $(r_A, c_B)$. So, for example in the product $w^t v$, the resulting dimensions of the product should be outer two numbers in $(4, 1)$, $(1, 4)$."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Matrices:\n",
"Recal that a matrix is a rectangular array of numbers (there could be other things in the array, but we will stick with numbers here). This is the form our data takes when we are using a Pandas data frame, for instance. An example of a matrix is here:\n",
"\n",
"\\begin{equation}\n",
" A = \\begin{bmatrix}\n",
" 1 & 3 & 5 & 7 \\\\\n",
" 2 & 4 & 6 & -3 \\\\\n",
" -1 & -5 & 10 & 6\n",
" \\end{bmatrix}\n",
"\\end{equation}\n",
"\n",
"The matrix above has 2 rows and 4 columns, and we will often indicate this saying it a $2 x 4$ matrix, or a matrix with dimensions $(2, 4)$. Here, the number of rows always comes first followed by the number of columns. Typically, vectors are denoted with lower case letters, and matrices are denoted with upper case. We can make a matrix in Numpy similar to how we made a row vector:"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"A = np.array([[1, 3, 5, 7], \n",
" [2, 4, 6, -3],\n",
" [-1, -5, 10, 6]])\n",
"print A"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"[[ 1 3 5 7]\n",
" [ 2 4 6 -3]\n",
" [-1 -5 10 6]]\n"
]
}
],
"prompt_number": 21
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can also easily make identity matrices in Numpy:"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"I = np.identity(5)\n",
"print I\n",
"\n",
"U = np.eye(5, k = -1)\n",
"print U\n"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"[[ 1. 0. 0. 0. 0.]\n",
" [ 0. 1. 0. 0. 0.]\n",
" [ 0. 0. 1. 0. 0.]\n",
" [ 0. 0. 0. 1. 0.]\n",
" [ 0. 0. 0. 0. 1.]]\n",
"[[ 0. 0. 0. 0. 0.]\n",
" [ 1. 0. 0. 0. 0.]\n",
" [ 0. 1. 0. 0. 0.]\n",
" [ 0. 0. 1. 0. 0.]\n",
" [ 0. 0. 0. 1. 0.]]\n"
]
}
],
"prompt_number": 22
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Multiplying a matrix by a vector\n",
"\n",
"If you don't recall how to multiply matrices together, or multiply vectors by matrices, have a look [here](http://en.wikipedia.org/wiki/Matrix_multiplication#Matrix_product_.28two_matrices.29). You will see that multiplication of a matrix and a vector and multiplication of two matrices are generalizations of the dot product.\n",
"\n",
"We will begin with right multiplying a matrix by a vector:"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"print A\n",
"print \"\"\n",
"print w_t\n",
"print \"\"\n",
"np.dot(A, w_t)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"[[ 1 3 5 7]\n",
" [ 2 4 6 -3]\n",
" [-1 -5 10 6]]\n",
"\n",
"[[ 4]\n",
" [ 67]\n",
" [-83]\n",
" [ 2]]\n",
"\n"
]
},
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 23,
"text": [
"array([[ -196],\n",
" [ -228],\n",
" [-1157]])"
]
}
],
"prompt_number": 23
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can also left multiply A by a vector:"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"x = np.array([[1, 3, -2]])\n",
"print x\n",
"print \"\"\n",
"np.dot(x, A)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"[[ 1 3 -2]]\n",
"\n"
]
},
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 24,
"text": [
"array([[ 9, 25, 3, -14]])"
]
}
],
"prompt_number": 24
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Matrix Multiplication and Matrix Inverses\n",
"\n",
"Just as we can multiply a vector and a matrix, we can also multiply matrices together. Also, for square matrices, we can find the matix inverse using Numpy's linalg module:"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"B = np.array([[-2, 1, 5], [3, 10, 6], [-5, -6, -7], [8, 10, 12]])\n",
"print A\n",
"print B\n",
"print A.shape\n",
"print B.shape\n",
"\n",
"C = np.dot(A, B)\n",
"print C\n",
"print C.shape"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"[[ 1 3 5 7]\n",
" [ 2 4 6 -3]\n",
" [-1 -5 10 6]]\n",
"[[-2 1 5]\n",
" [ 3 10 6]\n",
" [-5 -6 -7]\n",
" [ 8 10 12]]\n",
"(3, 4)\n",
"(4, 3)\n",
"[[ 38 71 72]\n",
" [-46 -24 -44]\n",
" [-15 -51 -33]]\n",
"(3, 3)\n"
]
}
],
"prompt_number": 25
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"C_inv = np.linalg.inv(C)\n",
"print C_inv\n",
"print np.dot(C, C_inv)\n",
"print np.round(np.dot(C, C_inv))"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"[[-0.05398171 -0.04940888 -0.05189977]\n",
" [-0.03189828 -0.00646888 -0.06097108]\n",
" [ 0.07383449 0.03245594 0.0875158 ]]\n",
"[[ 1.00000000e+00 0.00000000e+00 8.88178420e-16]\n",
" [ 0.00000000e+00 1.00000000e+00 0.00000000e+00]\n",
" [ 0.00000000e+00 0.00000000e+00 1.00000000e+00]]\n",
"[[ 1. 0. 0.]\n",
" [ 0. 1. 0.]\n",
" [ 0. 0. 1.]]\n"
]
}
],
"prompt_number": 26
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Above we used np.round() to round the result to 0 decimal places. Because of numerical imprecision, the result is not exactly the indentity matrix otherwise.\n",
"\n",
"### Eigenvalues and Eigenvectors\n",
"\n",
"Given a square matrix, we can also easily find the eigenvalues and eigenvectors for the matrix. Here linalg.eig() returns an array with eigenvalues together with an array that has eigenvectors as columns:"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"D = np.array([[2,1,1],\n",
" [3,2,1],\n",
" [1,2,3]])\n",
"\n",
"w, v = np.linalg.eig(D)\n",
"print w\n",
"print \"\"\n",
"print v\n",
"print \"\"\n",
"print \"The first eigenvector:\"\n",
"eig_vect_0 = v[:, 0]\n",
"print eig_vect_0\n",
"print \"\"\n",
"print \"Matrix D multiplied by the first eigenvector:\"\n",
"print np.dot(D, eig_vect_0)\n",
"print \"\"\n",
"print \"The first eigenvector muliplied by the first eigenvalue:\"\n",
"print w[0]*eig_vect_0\n",
"print \"\"\n",
"print \"They are equal as expected!!\""
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"[ 5.23606798 0.76393202 1. ]\n",
"\n",
"[[ 3.99086643e-01 1.02210514e-01 1.23263092e-15]\n",
" [ 5.87509797e-01 -7.63730854e-01 -7.07106781e-01]\n",
" [ 7.03961710e-01 6.37391711e-01 7.07106781e-01]]\n",
"\n",
"The first eigenvector:\n",
"[ 0.39908664 0.5875098 0.70396171]\n",
"\n",
"Matrix D multiplied by the first eigenvector:\n",
"[ 2.08964479 3.07624123 3.68599137]\n",
"\n",
"The first eigenvector muliplied by the first eigenvalue:\n",
"[ 2.08964479 3.07624123 3.68599137]\n",
"\n",
"They are equal as expected!!\n"
]
}
],
"prompt_number": 28
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Systems of Equations\n",
"\n",
"We can solve a system of equations of the form\n",
"\\begin{equation}\n",
" Ax = b\n",
"\\end{equation}\n",
"for a given vector $b$, matrix $A$ and unknown vector $x$. To do this we need to use linalg.solve():"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"#This is so that we can use matrix D, which we know is well behaved (invertible), but with the name A.\n",
"A = D\n",
"print \"A is the matrix:\"\n",
"print A\n",
"b = np.array([[3, 10, -1]]).T\n",
"print \"\"\n",
"print \"b is the column vector:\"\n",
"print b\n",
"print \"\"\n",
"print \"The solution x:\"\n",
"x = np.linalg.solve(A, b)\n",
"print x\n",
"print \"\"\n",
"print \"Checking that Ax equals b:\"\n",
"print np.dot(A, x)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"A is the matrix:\n",
"[[2 1 1]\n",
" [3 2 1]\n",
" [1 2 3]]\n",
"\n",
"b is the column vector:\n",
"[[ 3]\n",
" [10]\n",
" [-1]]\n",
"\n",
"The solution x:\n",
"[[ 0.75]\n",
" [ 6.25]\n",
" [-4.75]]\n",
"\n",
"Checking that Ax equals b:\n",
"[[ 3.]\n",
" [ 10.]\n",
" [ -1.]]\n"
]
}
],
"prompt_number": 13
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Working with Pandas\n",
"\n",
"Numpy plays well with Pandas, meaning it is fairly easy to convert Pandas dataframes to Numpy arrays and vice versa. This allows us to perform most of the same operations as above on data from Pandas dataframes.\n",
"\n",
"Below we have some made up data with observations for three temperatures. Suppose that we were trying to create a linear model with the three features, and we had already performed a regression to get a vector of coefficients (thetas). How do we compute predicitons?"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import pandas as pd\n",
"\n",
"temp_1 = [13, 11, 10, 9, 8, 8, 6, 5, 4, 4, 4, 3, 3, 2, 2, 2, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0]\n",
"temp_2 = [11, 5, 10, 7, 7, 6, 3, 0, 8, 4, 1, 4, 3, 7, 4, 2, 4, 3, 1, 0, 0, 2, 2, 2, 1, 0]\n",
"temp_3 = [9, 10, 5, 12, 9, 5, 2, 1, 5, 7, 1, 2, 2, 6, 2, 4, 3, 1, 2, 1, 0, 6, 2, 1, 0, 1]\n",
"\n",
"temperatures = {'temp 1': pd.Series(temp_1),\n",
" 'temp 2': pd.Series(temp_2),\n",
" 'temp 3': pd.Series(temp_3)}\n",
"\n",
"df = pd.DataFrame(temperatures)\n",
"print df.head()\n",
"\n",
"#converting the dataframe to a Numpy array\n",
"subset = np.array(df)\n",
"print subset[0:10, :]\n",
"\n",
"thetas = np.array([[1, 2, 3]]).T\n",
"\n",
"print subset.shape\n",
"print thetas.shape\n",
"\n",
"print np.dot(subset, thetas)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
" temp 1 temp 2 temp 3\n",
"0 13 11 9\n",
"1 11 5 10\n",
"2 10 10 5\n",
"3 9 7 12\n",
"4 8 7 9\n",
"[[13 11 9]\n",
" [11 5 10]\n",
" [10 10 5]\n",
" [ 9 7 12]\n",
" [ 8 7 9]\n",
" [ 8 6 5]\n",
" [ 6 3 2]\n",
" [ 5 0 1]\n",
" [ 4 8 5]\n",
" [ 4 4 7]]\n",
"(26, 3)\n",
"(3, 1)\n",
"[[62]\n",
" [51]\n",
" [45]\n",
" [59]\n",
" [49]\n",
" [35]\n",
" [18]\n",
" [ 8]\n",
" [35]\n",
" [33]\n",
" [ 9]\n",
" [17]\n",
" [15]\n",
" [34]\n",
" [16]\n",
" [18]\n",
" [18]\n",
" [10]\n",
" [ 9]\n",
" [ 4]\n",
" [ 1]\n",
" [22]\n",
" [10]\n",
" [ 7]\n",
" [ 2]\n",
" [ 3]]\n"
]
}
],
"prompt_number": 14
}
],
"metadata": {}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment