{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"___\n",
"\n",
"
\n",
"___\n",
"
\n",
"arr.min() returns 0 minimum\n",
"arr.var() returns 8.25 variance\n",
"arr.std() returns 2.8722813232690143 standard deviation\n",
""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Axis Logic\n",
"When working with 2-dimensional arrays (matrices) we have to consider rows and columns. This becomes very important when we get to the section on pandas. In array terms, axis 0 (zero) is the vertical axis (rows), and axis 1 is the horizonal axis (columns). These values (0,1) correspond to the order in which arr.shape values are returned.\n",
"\n",
"Let's see how this affects our summary statistic calculations from above."
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[ 1, 2, 3, 4],\n",
" [ 5, 6, 7, 8],\n",
" [ 9, 10, 11, 12]])"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"arr_2d = np.array([[1,2,3,4],[5,6,7,8],[9,10,11,12]])\n",
"arr_2d"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([15, 18, 21, 24])"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"arr_2d.sum(axis=0)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"By passing in axis=0, we're returning an array of sums along the vertical axis, essentially [(1+5+9), (2+6+10), (3+7+11), (4+8+12)]\n",
"\n",
"
"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(3, 4)"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"arr_2d.shape"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This tells us that arr_2d has 3 rows and 4 columns.\n",
"\n",
"In arr_2d.sum(axis=0) above, the first element in each row was summed, then the second element, and so forth.\n",
"\n",
"So what should arr_2d.sum(axis=1) return?"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# THINK ABOUT WHAT THIS WILL RETURN BEFORE RUNNING THE CELL!\n",
"arr_2d.sum(axis=1)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Great Job!\n",
"\n",
"That's all we need to know for now!"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.6.6"
}
},
"nbformat": 4,
"nbformat_minor": 1
}