Packages

From:https://campus.datacamp.com/courses/intro-to-python-for-data-science/chapter-3-functions-and-packages?ex=10

  • Import package

As a data scientist, some notions of geometry never hurt. Let's refresh some of the basics.We can do this by importing package.

import math

# Definition of radius
r = 0.43

# Import the math package
import math

# Calculate C
C = 2 * math.pi * r

# Calculate A
A = math.pi * r ** 2

# Build printout
print("Circumference: " + str(C))
print("Area: " + str(A))

  • Selective import

General imports, like import math, make all functionality from the mathpackage available to you. However, if you decide to only use a specific part of a package, you can always make your import more selective:

from math import pi

# Definition of radius
r = 192500

# Import radians function of math package
from math import radians #not radians()

# Travel distance of Moon over 12 degrees. Store in dist.
phi = radians(12)
dist = r * phi

# Print out dist
print(dist)

  • Different ways of importing

There are several ways to import packages and modules into Python. Depending on the import call, you'll have to use different Python code.

Suppose you want to use the function inv(), which is in the linalg subpackage of thescipy package. You want to be able to use this function as follows:

my_inv([[1,2], [3,4]])

could import as:
from scipy.linalg import inv as my_inv
 

Intro to Python for Data Science Learning 5 - Packages的更多相关文章

  1. Intro to Python for Data Science Learning 8 - NumPy: Basic Statistics

    NumPy: Basic Statistics from:https://campus.datacamp.com/courses/intro-to-python-for-data-science/ch ...

  2. Intro to Python for Data Science Learning 7 - 2D NumPy Arrays

    2D NumPy Arrays from:https://campus.datacamp.com/courses/intro-to-python-for-data-science/chapter-4- ...

  3. Intro to Python for Data Science Learning 2 - List

    List from:https://campus.datacamp.com/courses/intro-to-python-for-data-science/chapter-2-python-list ...

  4. Intro to Python for Data Science Learning 6 - NumPy

    NumPy From:https://campus.datacamp.com/courses/intro-to-python-for-data-science/chapter-4-numpy?ex=1 ...

  5. Intro to Python for Data Science Learning 4 - Methods

    Methods From:https://campus.datacamp.com/courses/intro-to-python-for-data-science/chapter-3-function ...

  6. Intro to Python for Data Science Learning 3 - functions

    Functions from:https://campus.datacamp.com/courses/intro-to-python-for-data-science/chapter-3-functi ...

  7. Intermediate Python for Data Science learning 2 - Histograms

    Histograms from:https://campus.datacamp.com/courses/intermediate-python-for-data-science/matplotlib? ...

  8. Intermediate Python for Data Science learning 1 - Basic plots with matplotlib

    Basic plots with matplotlib from:https://campus.datacamp.com/courses/intermediate-python-for-data-sc ...

  9. Intermediate Python for Data Science learning 3 - Customization

    Customization from:https://campus.datacamp.com/courses/intermediate-python-for-data-science/matplotl ...

随机推荐

  1. Css中!important的用法

    !important为开发者提供了一个增加样式权重的方法.应当注意的是!important是对整条样式的声明,包括这个样式的属性和属性值 <!DOCTYPE HTML> <html& ...

  2. Java反射机制获取Class文件

    JAVA反射机制是在运行状态中,对于任意一个类(class文件),都能够知道这个类的所有属性和方法:对于任意一个对象,都能够调用它的任意一个方法和属性:这种动态获取的信息以及动态调用对象方法的功能称为 ...

  3. jenkins之另辟蹊径实现根据svn项目实现智能选择

    项目要求,根据svn选择的trunk或branches及tags里的各分支,动态选择参数.一开始认为很简单,直接用jenkins中的List Subversion tags插件及active choi ...

  4. php base64转图片

    1.解析base64数据成图片 The problem is that data:image/bmp;base64, is included in the encoded contents. This ...

  5. Python面向对象之方法

    普通方法要执行类里面的方法是通过对象触发的 触发的时候把自己赋值给self 类方法 vim day7-7.py #!/usr/bin/python # -*- coding:utf-8 -*- cla ...

  6. 线性DP总结(LIS,LCS,LCIS,最长子段和)

    做了一段时间的线性dp的题目是时候做一个总结 线性动态规划无非就是在一个数组上搞嘛, 首先看一个最简单的问题: 一,最长字段和 下面为状态转移方程 for(int i=2;i<=n;i++) { ...

  7. HDU 2037 - 今年暑假不AC - [经典 选择不相交区间 问题]

    是一道很经典的选择不相交区间的问题. 关于选择不相交区间,可以参考刘汝佳.也可以参考:http://blog.csdn.net/dgq8211/article/details/7534488 以及模板 ...

  8. $obj

    <?php $obj = new stdClass(); for($w=0; $w<10; $w++){ $obj->$w= $w.'w'; $str = $w.'we'; $obj ...

  9. 2018/03/20 每日一个Linux命令 之 cp

    cp 命令用于复制文件/目录 cp [-参数] [复制文件] [复制成为的新文件] 参数(这里只介绍平常会用到的,之后的话遇到再回来补充) -f 覆盖已经存在的目标文件而不给出提示. -i 与-f选项 ...

  10. 洛谷P3966 单词 [TJOI2013] AC自动机

    正解:AC自动机 解题报告: 传送门! 先来提供一个40pts错解QAQ 首先看到这题就会想到AC自动机板子题2鸭!然后就照着那题的套路打一下,随便改一点儿,简单来说就是每次经过一个节点都要++,然后 ...