{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "ISRC Python Workshop: Baiscs II\n", "\n", "__Functions, File I/O and External Libraries__" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "@author: Zhiya Zuo\n", "\n", "@email: zhiya-zuo@uiowa.edu\n", "\n", "source: https://github.com/zhiyzuo/python-tutorial" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "---" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Functions" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Calling functions" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Previously, we have already made use of many built-in functions to facilitate programming. Function is a block of codes with input arguments (and, optionally, return values) for specific purposes. In Python ( and many other languages), a function call is as the following:\n", "\n", "```python\n", ">> output = function(input_argument)\n", "```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "For example:" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "ExecuteTime": { "end_time": "2018-10-25T17:47:37.407545Z", "start_time": "2018-10-25T17:47:37.389644Z" } }, "outputs": [ { "data": { "text/plain": [ "range(0, 5)" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "range(5)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now that Python 3 use [`iterator`](https://stackoverflow.com/questions/25653996/what-is-the-difference-between-list-and-iterator-in-python) for 'range' function, we can manually convert the output into `list` so that we can see the output explicitly" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "ExecuteTime": { "end_time": "2018-10-25T17:48:25.160955Z", "start_time": "2018-10-25T17:48:25.155505Z" } }, "outputs": [ { "data": { "text/plain": [ "[0, 1, 2, 3, 4]" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "list(range(5))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Define our own functions" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Note that we are not limited to built-in functions only. Let's now try make our own functions. Before that, we need to be clear on the structure of a function\n", "```python\n", "def func_name(arg1, arg2, arg3, ...):\n", " #####################\n", " # Do something here #\n", " #####################\n", " return output\n", "```\n", "\n", "\\* *`return output` is NOT required*" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In the following example, we make use of `sum`, a built-in function to sum up numeric iterables." ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "ExecuteTime": { "end_time": "2018-10-25T18:00:12.954116Z", "start_time": "2018-10-25T18:00:12.950910Z" } }, "outputs": [], "source": [ "def mySum(list_to_sum):\n", " return sum(list_to_sum)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "ExecuteTime": { "end_time": "2018-10-25T18:00:13.219092Z", "start_time": "2018-10-25T18:00:13.214135Z" } }, "outputs": [ { "data": { "text/plain": [ "10" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mySum(range(5))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "A more complicated one that does not use `sum` function." ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "ExecuteTime": { "end_time": "2018-10-25T18:00:55.632800Z", "start_time": "2018-10-25T18:00:55.628985Z" } }, "outputs": [], "source": [ "def mySumUsingLoop(list_to_sum):\n", " sum_ = list_to_sum[0]\n", " for item in list_to_sum[1:]:\n", " sum_ += item\n", " return sum_" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "ExecuteTime": { "end_time": "2018-10-25T18:00:55.894819Z", "start_time": "2018-10-25T18:00:55.887776Z" } }, "outputs": [ { "data": { "text/plain": [ "10" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mySumUsingLoop(range(5))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "*The two example functions are not doing anything interesting but just served as illustrations to build customized functions.*" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Libraries" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Often times, we need either internal or external help for complicated computation tasks. In these occasions, we need to _import libraries_. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Built-in libraries" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Python provides many built-in packages to prevent extra work on some common and useful functions\n", "\n", "We will use __math__ as an example." ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "ExecuteTime": { "end_time": "2018-10-25T18:11:30.413987Z", "start_time": "2018-10-25T18:11:30.411351Z" } }, "outputs": [], "source": [ "import math # use import to load a library" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To use functions from the library, do: `library_name.function_name`. For example, when we want to calculate the logarithm using a function from `math` library, we can do `math.log`" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "ExecuteTime": { "end_time": "2018-10-25T18:12:36.793378Z", "start_time": "2018-10-25T18:12:36.788201Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "e^x = e^3 = 20.085537\n", "log(x) = log(3) = 1.098612\n" ] } ], "source": [ "x = 3\n", "print(\"e^x = e^3 = %f\"%math.exp(x))\n", "print(\"log(x) = log(3) = %f\"%math.log(x))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can also import one specific function:" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "ExecuteTime": { "end_time": "2018-10-25T18:12:37.162731Z", "start_time": "2018-10-25T18:12:37.157103Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "20.085536923187668\n" ] } ], "source": [ "from math import exp # You can import a specific function\n", "print(exp(x)) # This way, you don't need to use math.exp but just exp" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Or all:" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "ExecuteTime": { "end_time": "2018-10-25T17:20:30.324507Z", "start_time": "2018-10-25T17:20:30.320936Z" } }, "outputs": [], "source": [ "from math import * # Import all functions" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "ExecuteTime": { "end_time": "2018-10-25T17:20:30.331795Z", "start_time": "2018-10-25T17:20:30.327483Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "20.085536923187668\n", "1.0986122886681098\n" ] } ], "source": [ "print(exp(x))\n", "print(log(x)) # Before importing math, calling `exp` or `log` will raise errors" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Depending on what you want to achieve, you may want to choose between importing a few or all (by `*`) functions within a package." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "---" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Quick Intro to Numpy" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Instead of using the native data structures, we use `numpy.ndarray` for data analytics most of the time. While they are not as \"flexible\" as lists, they are easy to use and have better performance. As Numpy's official documentation states:\n", "> NumPy’s main object is the homogeneous multidimensional array. It is a table of elements (usually numbers), all of the same type, indexed by a tuple of positive integers." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "As we were using it just now, the most common alias for `numpy` is `np`:" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "ExecuteTime": { "end_time": "2018-10-25T18:20:55.886804Z", "start_time": "2018-10-25T18:20:55.883788Z" } }, "outputs": [], "source": [ "import numpy as np" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Create arrays" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Depending on what types of analyses we are going to work on later, the most appropriate array initialization methods can be choosed." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##### By hand" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This is very similar to creating a list of elements manually, except that we wrap the list around by `np.array()`." ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "ExecuteTime": { "end_time": "2018-10-25T18:21:09.714465Z", "start_time": "2018-10-25T18:21:09.708143Z" } }, "outputs": [ { "data": { "text/plain": [ "array([1, 2, 3, 8])" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "arr = np.array([1,2,3,8])\n", "arr" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "ExecuteTime": { "end_time": "2018-10-25T18:21:10.376843Z", "start_time": "2018-10-25T18:21:10.372139Z" } }, "outputs": [ { "data": { "text/plain": [ "(4,)" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "arr.shape" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Multidimensional arrays: seperated by comma" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "1 by 4: 1 row and 4 columns" ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "ExecuteTime": { "end_time": "2018-10-25T18:22:13.908319Z", "start_time": "2018-10-25T18:22:13.903647Z" } }, "outputs": [ { "data": { "text/plain": [ "(1, 4)" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "arr = np.array([[1,2,3,8]])\n", "arr.shape" ] }, { "cell_type": "code", "execution_count": 16, "metadata": { "ExecuteTime": { "end_time": "2018-10-25T18:22:30.154253Z", "start_time": "2018-10-25T18:22:30.148702Z" } }, "outputs": [ { "data": { "text/plain": [ "array([[1, 2, 3, 8]])" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "arr" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "3 by 4: 3 row and 4 columns" ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "ExecuteTime": { "end_time": "2018-10-25T18:22:47.168037Z", "start_time": "2018-10-25T18:22:47.162787Z" } }, "outputs": [ { "data": { "text/plain": [ "(3, 4)" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "arr = np.array([[1,2,3,8], [3,2,3,2], [4,5,0,8]])\n", "arr.shape" ] }, { "cell_type": "code", "execution_count": 18, "metadata": { "ExecuteTime": { "end_time": "2018-10-25T18:22:47.618800Z", "start_time": "2018-10-25T18:22:47.613359Z" } }, "outputs": [ { "data": { "text/plain": [ "array([[1, 2, 3, 8],\n", " [3, 2, 3, 2],\n", " [4, 5, 0, 8]])" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "arr" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##### By functions" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "There are many special array initialization methods to call:" ] }, { "cell_type": "code", "execution_count": 19, "metadata": { "ExecuteTime": { "end_time": "2018-10-25T18:23:26.355528Z", "start_time": "2018-10-25T18:23:26.350971Z" } }, "outputs": [ { "data": { "text/plain": [ "array([[0, 0, 0, 0, 0],\n", " [0, 0, 0, 0, 0],\n", " [0, 0, 0, 0, 0]])" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.zeros([3,5], dtype=int)" ] }, { "cell_type": "code", "execution_count": 20, "metadata": { "ExecuteTime": { "end_time": "2018-10-25T17:20:32.915771Z", "start_time": "2018-10-25T17:20:32.908663Z" } }, "outputs": [ { "data": { "text/plain": [ "array([[1., 1., 1., 1., 1.],\n", " [1., 1., 1., 1., 1.],\n", " [1., 1., 1., 1., 1.]])" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.ones([3,5])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Arithmatic operations" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The rules are very similar to R: they are generally element wise" ] }, { "cell_type": "code", "execution_count": 21, "metadata": { "ExecuteTime": { "end_time": "2018-10-25T18:24:37.986303Z", "start_time": "2018-10-25T18:24:37.981265Z" } }, "outputs": [ { "data": { "text/plain": [ "array([[1, 2, 3, 8],\n", " [3, 2, 3, 2],\n", " [4, 5, 0, 8]])" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "arr" ] }, { "cell_type": "code", "execution_count": 22, "metadata": { "ExecuteTime": { "end_time": "2018-10-25T18:24:38.430440Z", "start_time": "2018-10-25T18:24:38.411917Z" } }, "outputs": [ { "data": { "text/plain": [ "array([[ 6, 12, 18, 48],\n", " [18, 12, 18, 12],\n", " [24, 30, 0, 48]])" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "arr * 6" ] }, { "cell_type": "code", "execution_count": 23, "metadata": { "ExecuteTime": { "end_time": "2018-10-25T17:20:32.958899Z", "start_time": "2018-10-25T17:20:32.951229Z" } }, "outputs": [ { "data": { "text/plain": [ "array([[-4, -3, -2, 3],\n", " [-2, -3, -2, -3],\n", " [-1, 0, -5, 3]])" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "arr - 5" ] }, { "cell_type": "code", "execution_count": 24, "metadata": { "ExecuteTime": { "end_time": "2018-10-25T17:20:32.970030Z", "start_time": "2018-10-25T17:20:32.963074Z" } }, "outputs": [ { "data": { "text/plain": [ "array([[2.71828183e+00, 7.38905610e+00, 2.00855369e+01, 2.98095799e+03],\n", " [2.00855369e+01, 7.38905610e+00, 2.00855369e+01, 7.38905610e+00],\n", " [5.45981500e+01, 1.48413159e+02, 1.00000000e+00, 2.98095799e+03]])" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.exp(arr)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##### Operation based on itself" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "There are many class methods to calculate some statistics of the array itself along some axis:\n", "- `axis=1` means row-wise\n", "- `axis=0` means column-wise" ] }, { "cell_type": "code", "execution_count": 25, "metadata": { "ExecuteTime": { "end_time": "2018-10-25T17:20:33.031146Z", "start_time": "2018-10-25T17:20:33.020661Z" } }, "outputs": [ { "data": { "text/plain": [ "array([[1, 2, 3, 8],\n", " [3, 2, 3, 2],\n", " [4, 5, 0, 8]])" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "arr" ] }, { "cell_type": "code", "execution_count": 26, "metadata": { "ExecuteTime": { "end_time": "2018-10-25T17:20:33.048518Z", "start_time": "2018-10-25T17:20:33.033767Z" } }, "outputs": [ { "data": { "text/plain": [ "8" ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "arr.max()" ] }, { "cell_type": "code", "execution_count": 27, "metadata": { "ExecuteTime": { "end_time": "2018-10-25T17:20:33.060765Z", "start_time": "2018-10-25T17:20:33.051750Z" } }, "outputs": [ { "data": { "text/plain": [ "array([8, 3, 8])" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "arr.max(axis=1)" ] }, { "cell_type": "code", "execution_count": 28, "metadata": { "ExecuteTime": { "end_time": "2018-10-25T17:20:33.072580Z", "start_time": "2018-10-25T17:20:33.064562Z" } }, "outputs": [ { "data": { "text/plain": [ "array([4, 5, 3, 8])" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "arr.max(axis=0)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Indexing and slicing" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The most important part is how to index and slice a `np.array`. It is actually very similar to `list`, except that we now may have more index elements because there are more than one dimension for most of the datasets in real life" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##### 1 dimensional case" ] }, { "cell_type": "code", "execution_count": 29, "metadata": { "ExecuteTime": { "end_time": "2018-10-25T18:28:39.875850Z", "start_time": "2018-10-25T18:28:39.862936Z" } }, "outputs": [ { "data": { "text/plain": [ "array([ 1, 2, 8, 100])" ] }, "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a1 = np.array([1,2,8,100])\n", "a1" ] }, { "cell_type": "code", "execution_count": 30, "metadata": { "ExecuteTime": { "end_time": "2018-10-25T18:28:40.194494Z", "start_time": "2018-10-25T18:28:40.187561Z" } }, "outputs": [ { "data": { "text/plain": [ "1" ] }, "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a1[0]" ] }, { "cell_type": "code", "execution_count": 31, "metadata": { "ExecuteTime": { "end_time": "2018-10-25T18:28:54.262749Z", "start_time": "2018-10-25T18:28:54.255392Z" } }, "outputs": [ { "data": { "text/plain": [ "8" ] }, "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a1[-2]" ] }, { "cell_type": "code", "execution_count": 32, "metadata": { "ExecuteTime": { "end_time": "2018-10-25T18:29:03.024941Z", "start_time": "2018-10-25T18:29:03.019955Z" } }, "outputs": [ { "data": { "text/plain": [ "array([ 1, 2, 100])" ] }, "execution_count": 32, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a1[[0,1,3]]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can also use boolean values to index\n", "- `True` means we want this element" ] }, { "cell_type": "code", "execution_count": 33, "metadata": { "ExecuteTime": { "end_time": "2018-10-25T18:29:28.874057Z", "start_time": "2018-10-25T18:29:28.869300Z" } }, "outputs": [ { "data": { "text/plain": [ "array([False, False, True, True])" ] }, "execution_count": 33, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a1 > 3" ] }, { "cell_type": "code", "execution_count": 34, "metadata": { "ExecuteTime": { "end_time": "2018-10-25T18:30:00.091948Z", "start_time": "2018-10-25T18:30:00.086799Z" } }, "outputs": [ { "data": { "text/plain": [ "array([ 8, 100])" ] }, "execution_count": 34, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a1[a1 > 3]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##### 2 dimensional case" ] }, { "cell_type": "code", "execution_count": 35, "metadata": { "ExecuteTime": { "end_time": "2018-10-25T18:30:01.277543Z", "start_time": "2018-10-25T18:30:01.270262Z" } }, "outputs": [ { "data": { "text/plain": [ "array([[1, 2, 3, 8],\n", " [3, 2, 3, 2],\n", " [4, 5, 0, 8]])" ] }, "execution_count": 35, "metadata": {}, "output_type": "execute_result" } ], "source": [ "arr" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Using only one number to index will lead to a subset of the original multidimenional array: also an array" ] }, { "cell_type": "code", "execution_count": 36, "metadata": { "ExecuteTime": { "end_time": "2018-10-25T18:30:15.881928Z", "start_time": "2018-10-25T18:30:15.877093Z" } }, "outputs": [ { "data": { "text/plain": [ "array([1, 2, 3, 8])" ] }, "execution_count": 36, "metadata": {}, "output_type": "execute_result" } ], "source": [ "arr[0]" ] }, { "cell_type": "code", "execution_count": 37, "metadata": { "ExecuteTime": { "end_time": "2018-10-25T18:30:21.305735Z", "start_time": "2018-10-25T18:30:21.299368Z" } }, "outputs": [ { "data": { "text/plain": [ "numpy.ndarray" ] }, "execution_count": 37, "metadata": {}, "output_type": "execute_result" } ], "source": [ "type(arr[0])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Since we have 2 dimensions now, there are 2 indices we can use for indexing the 2 dimensions respectively" ] }, { "cell_type": "code", "execution_count": 38, "metadata": { "ExecuteTime": { "end_time": "2018-10-25T18:35:00.665066Z", "start_time": "2018-10-25T18:35:00.661163Z" } }, "outputs": [ { "data": { "text/plain": [ "1" ] }, "execution_count": 38, "metadata": {}, "output_type": "execute_result" } ], "source": [ "arr[0,0]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can use `:` to indicate everything along that axis" ] }, { "cell_type": "code", "execution_count": 39, "metadata": { "ExecuteTime": { "end_time": "2018-10-25T18:35:01.023310Z", "start_time": "2018-10-25T18:35:01.012994Z" } }, "outputs": [ { "data": { "text/plain": [ "array([3, 2, 3, 2])" ] }, "execution_count": 39, "metadata": {}, "output_type": "execute_result" } ], "source": [ "arr[1]" ] }, { "cell_type": "code", "execution_count": 40, "metadata": { "ExecuteTime": { "end_time": "2018-10-25T18:35:01.286832Z", "start_time": "2018-10-25T18:35:01.277934Z" } }, "outputs": [ { "data": { "text/plain": [ "array([3, 2, 3, 2])" ] }, "execution_count": 40, "metadata": {}, "output_type": "execute_result" } ], "source": [ "arr[1, :]" ] }, { "cell_type": "code", "execution_count": 41, "metadata": { "ExecuteTime": { "end_time": "2018-10-25T18:35:01.415490Z", "start_time": "2018-10-25T18:35:01.405283Z" } }, "outputs": [ { "data": { "text/plain": [ "array([ True, True, True, True])" ] }, "execution_count": 41, "metadata": {}, "output_type": "execute_result" } ], "source": [ "arr[1,:] == arr[1]" ] }, { "cell_type": "code", "execution_count": 42, "metadata": { "ExecuteTime": { "end_time": "2018-10-25T18:35:01.582330Z", "start_time": "2018-10-25T18:35:01.573495Z" } }, "outputs": [ { "data": { "text/plain": [ "array([2, 2, 5])" ] }, "execution_count": 42, "metadata": {}, "output_type": "execute_result" } ], "source": [ "arr[:, 1]" ] } ], "metadata": { "hide_input": false, "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.9" }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": true, "sideBar": true, "skip_h1_title": false, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": false, "toc_position": { "height": "840px", "left": "0px", "right": "1111px", "top": "113px", "width": "253px" }, "toc_section_display": "block", "toc_window_display": true }, "varInspector": { "cols": { "lenName": 16, "lenType": 16, "lenVar": 40 }, "kernels_config": { "python": { "delete_cmd_postfix": "", "delete_cmd_prefix": "del ", "library": "var_list.py", "varRefreshCmd": "print(var_dic_list())" }, "r": { "delete_cmd_postfix": ") ", "delete_cmd_prefix": "rm(", "library": "var_list.r", "varRefreshCmd": "cat(var_dic_list()) " } }, "types_to_exclude": [ "module", "function", "builtin_function_or_method", "instance", "_Feature" ], "window_display": false } }, "nbformat": 4, "nbformat_minor": 4 }