{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Review of Matrices\n",
"\n",
"## Matrix Basics\n",
"\n",
"- Like vectors, matrices are also a type of numpy array. Unlike vectorsâ€”which consist of data organized in a single dimensionâ€”matrices consist of data organized along two dimensions in a grid. \n",
"- Like all numpy arrays, matrices are *homogenously typed*, meaning the data they hold must always be of the same type.\n",
"- All numpy arrays consist of a single-dimensional string of data and information on how that data should be \"folded\" to create an array. A vector is just data that is not folded, while a matrix is data that is folded into a grid. \n",
"- The shape of an array can be found in the `.shape` attribute.\n",
"- How an array is folded can be modified with the `.reshape()` method.\n",
"\n",
"## Subsetting Matrices\n",
"\n",
"- Subsetting matrices is just like subsetting vectors, except with two entries between the square brackets instead of one: `[ , ]`.\n",
"- The first entry in the square brackets relates to a location along the x-axis (rows), the second to the y-axis (columns).\n",
"- You must always pass two locations to subset a matrix. If you want all rows or all columns, simply pass a `:` (e.g., to get all of the columns in the first row, you would pass `my_matrix[0, :]`).\n",
"- Like vectors, you can subset using simple indexing using index values or ranges. This will return a view.\n",
"- Like vectors, you can also subset with fancy indexing or a Boolean vector.\n",
"- You can mix how you subset, and use a Boolean for rows and an index for columns.\n",
"- Subsetting on both rows and columns allows you to edit matrices in very powerful ways. "
]
}
],
"metadata": {
"interpreter": {
"hash": "3e0a5228cb9726a24d36227c69ed0d3aac98cecda769d1c9adb080711d57f90d"
},
"kernelspec": {
"display_name": "R",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}