{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "spare-diary", "metadata": {}, "outputs": [], "source": [ "# numpy高性能科学计算和数据分析的基础包,是 pandas等其他各种工具的基础\n", "# 主要功能:\n", " # dbarray 一个多纬数组结构,高效节省空间\n", " # 无需循环对整组数据 进行快速运算的数学函数\n", " # 线性代数,随机数生成和佛里叶变换功能" ] }, { "cell_type": "code", "execution_count": 2, "id": "perfect-burlington", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import random" ] }, { "cell_type": "code", "execution_count": 3, "id": "labeled-payday", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "7" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# 首先补习一下 random 方法\n", "random.randint(1,10) # 从1-10中 生成随机整数" ] }, { "cell_type": "code", "execution_count": 4, "id": "democratic-extreme", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.01012065801267803" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "random.random() # 生成一个随机数" ] }, { "cell_type": "code", "execution_count": 5, "id": "laden-battlefield", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3.234220387581025" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "random.uniform(1, 5) # 方法将随机生成一个实数,它在(3,5) 范围内。" ] }, { "cell_type": "code", "execution_count": 6, "id": "corporate-luxembourg", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([1, 2, 4, 5, 6, 8])" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# 把普通列表转换为 数组\n", "a = [1,2,4,5,6,8]\n", "np.array(a)" ] }, { "cell_type": "code", "execution_count": 7, "id": "nuclear-source", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[114.8113445129365, 105.03026077646373, 126.40819668276984, 144.02771362642457, 188.69914082688803]\n" ] }, { "data": { "text/plain": [ "array([ 780.71714269, 714.20577328, 859.57573744, 979.38845266,\n", " 1283.15415762])" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# 案例一: 已知道若干公司的市值(美元), 将其换算为人民币\n", "a = [random.uniform(100.0,200.0) for i in range(5)]\n", "print(a)\n", "a = np.array(a)\n", "x = 6.8\n", "a * x" ] }, { "cell_type": "code", "execution_count": 8, "id": "altered-pantyhose", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "45" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# 求和\n", "np.arange(10).sum()" ] }, { "cell_type": "code", "execution_count": 9, "id": "married-reliance", "metadata": {}, "outputs": [], "source": [ "# 案例二: 已知每件商品的价格和数量 求 每件商品的总价格和所有商品的总价格\n", "a = [random.uniform(100.0,200.0) for i in range(10)]\n", "a = np.array(a)\n", "b = [random.randint(1 ,20) for i in range(10)]\n", "b = np.array(b)" ] }, { "cell_type": "code", "execution_count": 10, "id": "threatened-master", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([ 536.91451279, 505.93632213, 2330.99761339, 327.7136931 ,\n", " 388.23558067, 3015.30411445, 341.09819457, 930.55884079,\n", " 3188.44631204, 1824.75147264])" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# 求每件上面的总价格\n", "a*b" ] }, { "cell_type": "code", "execution_count": 11, "id": "successful-minneapolis", "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/plain": [ "13389.956656579325" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# 所有商品的总价格\n", "(a*b).sum()" ] }, { "cell_type": "code", "execution_count": 12, "id": "tropical-posting", "metadata": {}, "outputs": [], "source": [ "# 数组\n", "# numpy 提供 ndarray 多纬数组对象\n", " # 数组和列表的区别\n", " # 1.数组对象内的元素类型必须相同\n", " # 2. 数组大小不可以修改\n", " \n", "# ndarray 数据类型\n", " # 布尔型: bool_\n", " # 整型: int_ int8 int16 int32 int64\n", " # 无符号整型: uint8 uint16 uint32 uni64\n", " # 浮点型: float_ float_16 float_32 float_64\n", " # 复数型: complex_ complex64 complex128" ] }, { "cell_type": "code", "execution_count": 13, "id": "lovely-mobile", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "dtype('int64')" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a = np.array(range(10))\n", "# 数据类型\n", "a.dtype" ] }, { "cell_type": "code", "execution_count": 14, "id": "intimate-merchant", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "10" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# 元素的个数\n", "a.size" ] }, { "cell_type": "code", "execution_count": 15, "id": "straight-vietnam", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a" ] }, { "cell_type": "code", "execution_count": 16, "id": "under-climate", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(10,)" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a.shape # 几纬 返回 几个数" ] }, { "cell_type": "code", "execution_count": 17, "id": "seeing-caribbean", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "6" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# 二维数组\n", "a = np.array([[1,2,3],[4,5,6]])\n", "a.size # size 返回数组的元素个数" ] }, { "cell_type": "code", "execution_count": 18, "id": "physical-committee", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[1, 2, 3],\n", " [4, 5, 6]])" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a" ] }, { "cell_type": "code", "execution_count": 19, "id": "infectious-actor", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(2, 3)" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# 返回数组是 几*几\n", "a.shape # 2行 3列" ] }, { "cell_type": "code", "execution_count": 20, "id": "vocal-crime", "metadata": {}, "outputs": [], "source": [ "# 三维数组\n", "a = np.array([[[1,2,3,4],[4,5,6,6]],[[7,3,4,5],[7,8,9,5]],[[7,3,4,5],[7,8,9,1]]])" ] }, { "cell_type": "code", "execution_count": 21, "id": "integral-bumper", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[[1, 2, 3, 4],\n", " [4, 5, 6, 6]],\n", "\n", " [[7, 3, 4, 5],\n", " [7, 8, 9, 5]],\n", "\n", " [[7, 3, 4, 5],\n", " [7, 8, 9, 1]]])" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a" ] }, { "cell_type": "code", "execution_count": 22, "id": "handled-nature", "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/plain": [ "24" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a.size # 元素个数" ] }, { "cell_type": "code", "execution_count": 23, "id": "polish-nickel", "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/plain": [ "(3, 2, 4)" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a.shape # 3页 2行 4列 " ] }, { "cell_type": "code", "execution_count": 24, "id": "gothic-asthma", "metadata": {}, "outputs": [], "source": [ "a = np.array([[1,2,3],[4,5,6]])" ] }, { "cell_type": "code", "execution_count": 25, "id": "established-chancellor", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[1, 2, 3],\n", " [4, 5, 6]])" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a" ] }, { "cell_type": "code", "execution_count": 26, "id": "competitive-devil", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[1, 4],\n", " [2, 5],\n", " [3, 6]])" ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a.T # 转置 " ] }, { "cell_type": "code", "execution_count": 27, "id": "british-going", "metadata": {}, "outputs": [], "source": [ "# ndim" ] }, { "cell_type": "code", "execution_count": 28, "id": "alternate-pencil", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a = np.array([[1,2,3],[4,5,6]])\n", "a.ndim # 查看数组的 纬度" ] }, { "cell_type": "code", "execution_count": 29, "id": "yellow-vegetarian", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1" ] }, "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a = np.array(range(5))\n", "a.ndim # 查看数组的 纬度" ] }, { "cell_type": "code", "execution_count": 30, "id": "younger-kitchen", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0.])" ] }, "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a = np.zeros(10) # 创建全是 0 的数组\n", "a" ] }, { "cell_type": "code", "execution_count": 31, "id": "floppy-scroll", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "dtype('float64')" ] }, "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a.dtype # 类型为 float64" ] }, { "cell_type": "code", "execution_count": 32, "id": "civil-miniature", "metadata": {}, "outputs": [], "source": [ "a = np.zeros(10, dtype='int') # 指定创建的类型" ] }, { "cell_type": "code", "execution_count": 33, "id": "collectible-dispute", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])" ] }, "execution_count": 33, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a" ] }, { "cell_type": "code", "execution_count": 34, "id": "damaged-ontario", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "dtype('int64')" ] }, "execution_count": 34, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a.dtype" ] }, { "cell_type": "code", "execution_count": 35, "id": "active-third", "metadata": {}, "outputs": [], "source": [ "a = np.ones(10) # 创建 全是 1 的数组" ] }, { "cell_type": "code", "execution_count": 36, "id": "champion-parent", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([1., 1., 1., 1., 1., 1., 1., 1., 1., 1.])" ] }, "execution_count": 36, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a" ] }, { "cell_type": "code", "execution_count": 37, "id": "quick-simon", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([-1.49166815e-154, -1.49166815e-154, 4.94065646e-323,\n", " 0.00000000e+000, 0.00000000e+000, 0.00000000e+000,\n", " 0.00000000e+000, 0.00000000e+000, 0.00000000e+000,\n", " 0.00000000e+000, 0.00000000e+000, 0.00000000e+000,\n", " 0.00000000e+000, 0.00000000e+000, 0.00000000e+000,\n", " 4.98131536e+151, -1.49166815e-154, -2.68679007e+154,\n", " -1.49166815e-154, 1.39500959e-308])" ] }, "execution_count": 37, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a = np.empty(20) # 创建 空 数组\n", "a" ] }, { "cell_type": "code", "execution_count": 38, "id": "serious-employee", "metadata": {}, "outputs": [], "source": [ "# arange 和普通的 range差不多 有一些区别" ] }, { "cell_type": "code", "execution_count": 39, "id": "creative-sunglasses", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])" ] }, "execution_count": 39, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.arange(10)" ] }, { "cell_type": "code", "execution_count": 40, "id": "enhanced-heritage", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([2, 5, 8])" ] }, "execution_count": 40, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.arange(2,10,3) # 步长" ] }, { "cell_type": "code", "execution_count": 41, "id": "directed-trick", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([2. , 2.5, 3. , 3.5, 4. , 4.5, 5. , 5.5, 6. , 6.5, 7. , 7.5, 8. ,\n", " 8.5, 9. , 9.5])" ] }, "execution_count": 41, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.arange(2,10,0.5) # 步长 可以为小数" ] }, { "cell_type": "code", "execution_count": 42, "id": "crazy-adaptation", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([ 0., 10.])" ] }, "execution_count": 42, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# linspace # 把 0-10 分成 2份 2 为份数 间隔一样\n", "np.linspace(0,10,2)" ] }, { "cell_type": "code", "execution_count": 43, "id": "built-recruitment", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([ 0. , 3.33333333, 6.66666667, 10. ])" ] }, "execution_count": 43, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.linspace(0,10,4) # 把 0-10 分成 3份 3为份数 间隔一样" ] }, { "cell_type": "code", "execution_count": 44, "id": "future-anaheim", "metadata": {}, "outputs": [], "source": [ "############# ndarray 批量运算" ] }, { "cell_type": "code", "execution_count": 45, "id": "duplicate-miller", "metadata": {}, "outputs": [], "source": [ "a = np.arange(10)" ] }, { "cell_type": "code", "execution_count": 46, "id": "floating-theology", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])" ] }, "execution_count": 46, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a" ] }, { "cell_type": "code", "execution_count": 47, "id": "presidential-morgan", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([0. , 0.33333333, 0.66666667, 1. , 1.33333333,\n", " 1.66666667, 2. , 2.33333333, 2.66666667, 3. ])" ] }, "execution_count": 47, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a/3" ] }, { "cell_type": "code", "execution_count": 48, "id": "british-microwave", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/usr/local/lib/python3.7/site-packages/ipykernel_launcher.py:1: RuntimeWarning: divide by zero encountered in true_divide\n", " \"\"\"Entry point for launching an IPython kernel.\n" ] }, { "data": { "text/plain": [ "array([ inf, 3. , 1.5 , 1. , 0.75 ,\n", " 0.6 , 0.5 , 0.42857143, 0.375 , 0.33333333])" ] }, "execution_count": 48, "metadata": {}, "output_type": "execute_result" } ], "source": [ "3/a" ] }, { "cell_type": "code", "execution_count": 49, "id": "perfect-interval", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])" ] }, "execution_count": 49, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a+1" ] }, { "cell_type": "code", "execution_count": 50, "id": "editorial-snapshot", "metadata": {}, "outputs": [], "source": [ "b = np.arange(10,20)" ] }, { "cell_type": "code", "execution_count": 51, "id": "seven-bangkok", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([10, 11, 12, 13, 14, 15, 16, 17, 18, 19])" ] }, "execution_count": 51, "metadata": {}, "output_type": "execute_result" } ], "source": [ "b" ] }, { "cell_type": "code", "execution_count": 52, "id": "cleared-animation", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([10, 12, 14, 16, 18, 20, 22, 24, 26, 28])" ] }, "execution_count": 52, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a+b # 两个数组运算" ] }, { "cell_type": "code", "execution_count": 53, "id": "skilled-favorite", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([ True, True, True, True, True, True, True, True, True,\n", " True])" ] }, "execution_count": 53, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a5] # 布尔型索引" ] }, { "cell_type": "code", "execution_count": 78, "id": "senior-conditions", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([False, True, True, False, True, True, True, False, True,\n", " True])" ] }, "execution_count": 78, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# 原理 数组与标量的运算\n", "a>5" ] }, { "cell_type": "code", "execution_count": 79, "id": "original-making", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([ 5, 9, 6, 5, 7, 6, 10, 2, 8, 7])" ] }, "execution_count": 79, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a" ] }, { "cell_type": "code", "execution_count": 80, "id": "secret-karen", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([ 6, 6, 10, 8])" ] }, "execution_count": 80, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a[(a>5) & (a%2==0)]" ] }, { "cell_type": "code", "execution_count": 81, "id": "secondary-liability", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([ 9, 6, 7, 6, 10, 2, 8, 7])" ] }, "execution_count": 81, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a[(a>5) | (a%2==0)]" ] }, { "cell_type": "code", "execution_count": 82, "id": "characteristic-compiler", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([ 5, 9, 6, 5, 7, 6, 10, 2, 8, 7])" ] }, "execution_count": 82, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a" ] }, { "cell_type": "code", "execution_count": 83, "id": "gentle-eight", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([9, 6, 5])" ] }, "execution_count": 83, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a[[1,2,3]] # 花式索引 可以直接把索引写成一个列表 取对应的值" ] }, { "cell_type": "code", "execution_count": 84, "id": "creative-comedy", "metadata": {}, "outputs": [], "source": [ "a=np.arange(20).reshape(4,5)" ] }, { "cell_type": "code", "execution_count": 85, "id": "distributed-romania", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[ 0, 1, 2, 3, 4],\n", " [ 5, 6, 7, 8, 9],\n", " [10, 11, 12, 13, 14],\n", " [15, 16, 17, 18, 19]])" ] }, "execution_count": 85, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a" ] }, { "cell_type": "code", "execution_count": 86, "id": "rural-coupon", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([7, 8])" ] }, "execution_count": 86, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a[1,2:4]" ] }, { "cell_type": "code", "execution_count": 87, "id": "activated-advocacy", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([8, 9])" ] }, "execution_count": 87, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a[1,a[0]>2] " ] }, { "cell_type": "code", "execution_count": 88, "id": "cathedral-alloy", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[ 6, 8],\n", " [16, 18]])" ] }, "execution_count": 88, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a[[1,3],:][:,[1,3]] # 先取2,3行的所有列的值, 再取所有行的 1,3 列" ] }, { "cell_type": "code", "execution_count": 89, "id": "intermediate-chance", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([ 6, 18])" ] }, "execution_count": 89, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a[[1,3],[1,3]] # 两边都是花式索引 作用不一样 需要特殊注意" ] }, { "cell_type": "code", "execution_count": 90, "id": "perfect-right", "metadata": {}, "outputs": [], "source": [ "########## numpy 通用函数" ] }, { "cell_type": "code", "execution_count": 91, "id": "sustained-better", "metadata": {}, "outputs": [], "source": [ "# 一元函数 asb sqrt ceil floor rint trunc modf isnan isinf\n", "# 二元函数 maximum mininum" ] }, { "cell_type": "code", "execution_count": 92, "id": "curious-clinic", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([-5, -4, -3, -2, -1, 0, 1, 2, 3, 4])" ] }, "execution_count": 92, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a=np.arange(-5,5)\n", "a" ] }, { "cell_type": "code", "execution_count": 93, "id": "lasting-classification", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([5, 4, 3, 2, 1, 0, 1, 2, 3, 4])" ] }, "execution_count": 93, "metadata": {}, "output_type": "execute_result" } ], "source": [ "abs(a)" ] }, { "cell_type": "code", "execution_count": 94, "id": "tested-decimal", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([-5, -4, -3, -2, -1, 0, 1, 2, 3, 4])" ] }, "execution_count": 94, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a" ] }, { "cell_type": "code", "execution_count": 95, "id": "approved-requirement", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([5, 4, 3, 2, 1, 0, 1, 2, 3, 4])" ] }, "execution_count": 95, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.abs(a)" ] }, { "cell_type": "code", "execution_count": 96, "id": "temporal-criticism", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([-5, -4, -3, -2, -1, 0, 1, 2, 3, 4])" ] }, "execution_count": 96, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# 开方\n", "a" ] }, { "cell_type": "code", "execution_count": 97, "id": "answering-navigator", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/usr/local/lib/python3.7/site-packages/ipykernel_launcher.py:1: RuntimeWarning: invalid value encountered in sqrt\n", " \"\"\"Entry point for launching an IPython kernel.\n" ] }, { "data": { "text/plain": [ "array([ nan, nan, nan, nan, nan,\n", " 0. , 1. , 1.41421356, 1.73205081, 2. ])" ] }, "execution_count": 97, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.sqrt(a)" ] }, { "cell_type": "code", "execution_count": 98, "id": "accompanied-reply", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1" ] }, "execution_count": 98, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# int 取整数 向 0 取整数\n", "a=1.6\n", "int(a)" ] }, { "cell_type": "code", "execution_count": 99, "id": "million-newspaper", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1.6" ] }, "execution_count": 99, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a" ] }, { "cell_type": "code", "execution_count": 100, "id": "exclusive-spare", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2" ] }, "execution_count": 100, "metadata": {}, "output_type": "execute_result" } ], "source": [ "round(a) # round 四舍五入 " ] }, { "cell_type": "code", "execution_count": 101, "id": "decimal-cigarette", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "-2" ] }, "execution_count": 101, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import math \n", "a=-1.6\n", "math.floor(a) # 向下取整" ] }, { "cell_type": "code", "execution_count": 102, "id": "sensitive-scotland", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1" ] }, "execution_count": 102, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a=1.6\n", "math.floor(a) # 向下取整\n" ] }, { "cell_type": "code", "execution_count": 103, "id": "angry-planning", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2" ] }, "execution_count": 103, "metadata": {}, "output_type": "execute_result" } ], "source": [ "math.ceil(1.1) # 向上取整数" ] }, { "cell_type": "code", "execution_count": 104, "id": "native-domain", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "-1" ] }, "execution_count": 104, "metadata": {}, "output_type": "execute_result" } ], "source": [ "math.ceil(-1.1) # 向上取整数" ] }, { "cell_type": "code", "execution_count": 105, "id": "applicable-evaluation", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([-5.1, -3.1, -1.1, 0.9, 2.9, 4.9])" ] }, "execution_count": 105, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a=np.arange(-5.1,5.5,2)\n", "a" ] }, { "cell_type": "code", "execution_count": 106, "id": "endangered-florist", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([-6., -4., -2., 0., 2., 4.])" ] }, "execution_count": 106, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.floor(a) # # 向下取整" ] }, { "cell_type": "code", "execution_count": 107, "id": "virtual-evening", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([-5., -3., -1., 1., 3., 5.])" ] }, "execution_count": 107, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.ceil(a) # 向上取整数" ] }, { "cell_type": "code", "execution_count": 108, "id": "liquid-norwegian", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([-5., -3., -1., 1., 3., 5.])" ] }, "execution_count": 108, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.round(a) # 四舍五入" ] }, { "cell_type": "code", "execution_count": 109, "id": "understood-methodology", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([-5., -3., -1., 0., 2., 4.])" ] }, "execution_count": 109, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.trunc(a) # 向 0 取整数 和 int类似" ] }, { "cell_type": "code", "execution_count": 110, "id": "amino-creator", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(array([-0.1, -0.1, -0.1, 0.9, 0.9, 0.9]),\n", " array([-5., -3., -1., 0., 2., 4.]))" ] }, "execution_count": 110, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.modf(a) # 把整数部分和小数部分 分开" ] }, { "cell_type": "code", "execution_count": 111, "id": "metric-subsection", "metadata": {}, "outputs": [], "source": [ "### isnan isinf 举例说明\n", "# nan(not a Number) 不等于任何浮点数(nan != nan)\n", "# inf(infinity) 比任何浮点数都大\n", "# numpy 中创建中创建特殊值 np.nan np.inf\n", "# 在数据分析中 nan常被用作表示数据缺失值" ] }, { "cell_type": "code", "execution_count": 112, "id": "prescription-hungary", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([0, 1, 2, 3, 4])" ] }, "execution_count": 112, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a = np.arange(0,5)\n", "a" ] }, { "cell_type": "code", "execution_count": 113, "id": "facial-investing", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/usr/local/lib/python3.7/site-packages/ipykernel_launcher.py:1: RuntimeWarning: divide by zero encountered in true_divide\n", " \"\"\"Entry point for launching an IPython kernel.\n" ] }, { "data": { "text/plain": [ "array([ inf, 5. , 2.5 , 1.66666667, 1.25 ])" ] }, "execution_count": 113, "metadata": {}, "output_type": "execute_result" } ], "source": [ "5/a" ] }, { "cell_type": "code", "execution_count": 114, "id": "responsible-humanity", "metadata": {}, "outputs": [], "source": [ "a = np.arange(-5,5)" ] }, { "cell_type": "code", "execution_count": 115, "id": "indie-fault", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([-5, -4, -3, -2, -1, 0, 1, 2, 3, 4])" ] }, "execution_count": 115, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a" ] }, { "cell_type": "code", "execution_count": 116, "id": "musical-asbestos", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/usr/local/lib/python3.7/site-packages/ipykernel_launcher.py:1: RuntimeWarning: invalid value encountered in sqrt\n", " \"\"\"Entry point for launching an IPython kernel.\n" ] }, { "data": { "text/plain": [ "array([ nan, nan, nan, nan, nan,\n", " 0. , 1. , 1.41421356, 1.73205081, 2. ])" ] }, "execution_count": 116, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.sqrt(a)" ] }, { "cell_type": "code", "execution_count": 117, "id": "fitted-custody", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 117, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.nan == np.nan # np.nan 不等于任何值" ] }, { "cell_type": "code", "execution_count": 118, "id": "persistent-establishment", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([-5, -4, -3, -2, -1, 0, 1, 2, 3, 4])" ] }, "execution_count": 118, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a = np.arange(-5,5)\n", "a" ] }, { "cell_type": "code", "execution_count": 119, "id": "presidential-sunrise", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/usr/local/lib/python3.7/site-packages/ipykernel_launcher.py:1: RuntimeWarning: invalid value encountered in true_divide\n", " \"\"\"Entry point for launching an IPython kernel.\n" ] }, { "data": { "text/plain": [ "array([ 1., 1., 1., 1., 1., nan, 1., 1., 1., 1.])" ] }, "execution_count": 119, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a/a" ] }, { "cell_type": "code", "execution_count": 120, "id": "compound-jacksonville", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/usr/local/lib/python3.7/site-packages/ipykernel_launcher.py:1: RuntimeWarning: invalid value encountered in true_divide\n", " \"\"\"Entry point for launching an IPython kernel.\n" ] } ], "source": [ "b = a/a" ] }, { "cell_type": "code", "execution_count": 121, "id": "fabulous-cemetery", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([ 1., 1., 1., 1., 1., nan, 1., 1., 1., 1.])" ] }, "execution_count": 121, "metadata": {}, "output_type": "execute_result" } ], "source": [ "b" ] }, { "cell_type": "code", "execution_count": 122, "id": "intellectual-university", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([False, False, False, False, False, True, False, False, False,\n", " False])" ] }, "execution_count": 122, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.isnan(b)" ] }, { "cell_type": "code", "execution_count": 123, "id": "macro-church", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([1., 1., 1., 1., 1., 1., 1., 1., 1.])" ] }, "execution_count": 123, "metadata": {}, "output_type": "execute_result" } ], "source": [ "b[~ np.isnan(b)] # 用 ~ 把非 nan的删掉" ] }, { "cell_type": "code", "execution_count": 124, "id": "charged-timer", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([3, 4, 5, 6, 7])" ] }, "execution_count": 124, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# inf\n", "a = np.array([3,4,5,6,7])\n", "a" ] }, { "cell_type": "code", "execution_count": 125, "id": "collective-fence", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([5, 0, 8, 2, 0])" ] }, "execution_count": 125, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# inf\n", "b = np.array([5,0,8,2,0])\n", "b" ] }, { "cell_type": "code", "execution_count": 126, "id": "trying-asset", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/usr/local/lib/python3.7/site-packages/ipykernel_launcher.py:1: RuntimeWarning: divide by zero encountered in true_divide\n", " \"\"\"Entry point for launching an IPython kernel.\n" ] }, { "data": { "text/plain": [ "array([0.6 , inf, 0.625, 3. , inf])" ] }, "execution_count": 126, "metadata": {}, "output_type": "execute_result" } ], "source": [ "c = a/b\n", "c" ] }, { "cell_type": "code", "execution_count": 127, "id": "palestinian-midwest", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 127, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.inf == np.inf" ] }, { "cell_type": "code", "execution_count": 128, "id": "cooked-budget", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([0.6 , 0.625, 3. ])" ] }, "execution_count": 128, "metadata": {}, "output_type": "execute_result" } ], "source": [ "c[~np.isinf(c)] # 把所有 非 inf的值取出来" ] }, { "cell_type": "code", "execution_count": 129, "id": "hollywood-client", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([0.6 , 0.625, 3. ])" ] }, "execution_count": 129, "metadata": {}, "output_type": "execute_result" } ], "source": [ "c[c!=np.inf] # inf也可以这么写" ] }, { "cell_type": "code", "execution_count": 130, "id": "double-henry", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([3, 4, 5, 6, 7])" ] }, "execution_count": 130, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a" ] }, { "cell_type": "code", "execution_count": 131, "id": "homeless-storm", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([ 8, 6, 1, 9, 10])" ] }, "execution_count": 131, "metadata": {}, "output_type": "execute_result" } ], "source": [ "b = np.array([8,6,1,9,10])\n", "b" ] }, { "cell_type": "code", "execution_count": 132, "id": "acute-cheat", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([ 8, 6, 5, 9, 10])" ] }, "execution_count": 132, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.maximum(a,b) # 把最大的值合并为一个列表" ] }, { "cell_type": "code", "execution_count": 133, "id": "civil-provider", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([3, 4, 5, 6, 7])" ] }, "execution_count": 133, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a" ] }, { "cell_type": "code", "execution_count": 134, "id": "heard-demonstration", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "25" ] }, "execution_count": 134, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a.sum() # 求和" ] }, { "cell_type": "code", "execution_count": 135, "id": "leading-springfield", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3" ] }, "execution_count": 135, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a.min() # 最小数" ] }, { "cell_type": "code", "execution_count": 136, "id": "eastern-corrections", "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/plain": [ "7" ] }, "execution_count": 136, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a.max() # 最大数" ] }, { "cell_type": "code", "execution_count": 137, "id": "partial-isaac", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "5.0" ] }, "execution_count": 137, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a.mean() # 求平均数" ] }, { "cell_type": "code", "execution_count": 138, "id": "authorized-dining", "metadata": {}, "outputs": [], "source": [ "# 求标准差 std 和 方差 var" ] }, { "cell_type": "code", "execution_count": 139, "id": "together-chaos", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([3, 4, 5, 6])" ] }, "execution_count": 139, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a = np.array([3,4,5,6])\n", "a" ] }, { "cell_type": "code", "execution_count": 140, "id": "disabled-alignment", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1.25" ] }, "execution_count": 140, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a.var()" ] }, { "cell_type": "code", "execution_count": 141, "id": "brazilian-interest", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "4.5" ] }, "execution_count": 141, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a.mean()" ] }, { "cell_type": "code", "execution_count": 142, "id": "healthy-gentleman", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1.25" ] }, "execution_count": 142, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# 方差 每个数-均数 的方 最后 加起来 / 总个数 == 方差\n", "# 整组数据的离散程度\n", "((3-4.5)**2+(4-4.5)**2+(5-4.5)**2+(6-4.5)**2)/4" ] }, { "cell_type": "code", "execution_count": 143, "id": "hazardous-continent", "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/plain": [ "1.118033988749895" ] }, "execution_count": 143, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a.std() # 标准差" ] }, { "cell_type": "code", "execution_count": 144, "id": "amazing-restriction", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([3, 4, 5, 6])" ] }, "execution_count": 144, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a" ] }, { "cell_type": "code", "execution_count": 145, "id": "duplicate-controversy", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3" ] }, "execution_count": 145, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a.argmax() # 求最大索引" ] }, { "cell_type": "code", "execution_count": 146, "id": "golden-celebration", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0" ] }, "execution_count": 146, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a.argmin() # 求最小索引" ] }, { "cell_type": "code", "execution_count": 147, "id": "asian-indonesia", "metadata": {}, "outputs": [], "source": [ "### numpy 随机数生成\n", "# rand 给定形状 产生随机数组 0-1之间的数\n", "# randint 给定形状 生成随机整数\n", "# choice 给定形状 产生随机选择\n", "# shuffle 与 random.shuffle相同\n", "# uniform 给定形状产生随机数组" ] }, { "cell_type": "code", "execution_count": 148, "id": "interstate-evanescence", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.6899648787322505" ] }, "execution_count": 148, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# 首先复习 random\n", "import random\n", "random.random()" ] }, { "cell_type": "code", "execution_count": 149, "id": "human-carter", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0" ] }, "execution_count": 149, "metadata": {}, "output_type": "execute_result" } ], "source": [ "random.randint(0,10)" ] }, { "cell_type": "code", "execution_count": 150, "id": "equivalent-header", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "5" ] }, "execution_count": 150, "metadata": {}, "output_type": "execute_result" } ], "source": [ "random.choice([1,2,3,5])" ] }, { "cell_type": "code", "execution_count": 151, "id": "correct-burton", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[1, 2, 3, 5]" ] }, "execution_count": 151, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a = [1,2,3,5]\n", "a" ] }, { "cell_type": "code", "execution_count": 152, "id": "affiliated-smooth", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[5, 2, 1, 3]" ] }, "execution_count": 152, "metadata": {}, "output_type": "execute_result" } ], "source": [ "random.shuffle(a) # 打乱列表\n", "a" ] }, { "cell_type": "code", "execution_count": 153, "id": "measured-finish", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "7" ] }, "execution_count": 153, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.random.randint(1,10)" ] }, { "cell_type": "code", "execution_count": 154, "id": "cloudy-probe", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([8, 5, 9, 5, 5])" ] }, "execution_count": 154, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.random.randint(1,10,5) # 可以直接生成数组 1-10之间 长度为 5" ] }, { "cell_type": "code", "execution_count": 155, "id": "perceived-enemy", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[5, 1],\n", " [6, 4],\n", " [8, 2]])" ] }, "execution_count": 155, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.random.randint(1,10,(3,2)) #生成一个 3行2列的 二维数组" ] }, { "cell_type": "code", "execution_count": 156, "id": "fatty-center", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[[1, 6, 9, 4],\n", " [1, 3, 8, 1],\n", " [7, 4, 1, 1]],\n", "\n", " [[8, 6, 5, 2],\n", " [1, 5, 7, 6],\n", " [3, 6, 6, 6]]])" ] }, "execution_count": 156, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.random.randint(1,10,(2,3,4)) #生成一个 2页 3行4 列的 三纬数组" ] }, { "cell_type": "code", "execution_count": 157, "id": "cooked-miracle", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([0.1210554 , 0.29213791, 0.7731894 , 0.93614371, 0.48178126,\n", " 0.22422172, 0.75228336, 0.87118411, 0.81347288, 0.28473431])" ] }, "execution_count": 157, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.random.rand(10) # rand产生随机数组 0-1之间的数 长度为 10" ] }, { "cell_type": "code", "execution_count": 158, "id": "actual-filing", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([0.57751143, 0.52700252])" ] }, "execution_count": 158, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.random.rand(2) # rand产生随机数组 0-1之间的数 长度为 2" ] }, { "cell_type": "code", "execution_count": 159, "id": "statutory-grant", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([2, 1, 2, 1])" ] }, "execution_count": 159, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.random.choice([1,2,3,4,1],4) # choice 给定形状 产生随机选择 这里选择 4个" ] }, { "cell_type": "code", "execution_count": 160, "id": "mathematical-expense", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([3, 8, 8, 5, 4])" ] }, "execution_count": 160, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a = np.random.randint(1,10,5)\n", "a" ] }, { "cell_type": "code", "execution_count": 161, "id": "incomplete-brand", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([8, 3, 4, 5, 8])" ] }, "execution_count": 161, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.random.shuffle(a) # 打乱 数组 a 的顺序\n", "a" ] }, { "cell_type": "code", "execution_count": 162, "id": "confirmed-terrorist", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([3.35828963, 2.54463016, 2.81469473, 3.11184301, 3.59685107])" ] }, "execution_count": 162, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.random.uniform(2.0,4.0,5) # 生成5个 随机小数" ] }, { "cell_type": "code", "execution_count": null, "id": "forced-uzbekistan", "metadata": {}, "outputs": [], "source": [] } ], "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.7.7" } }, "nbformat": 4, "nbformat_minor": 5 }