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. 公钥基础设施体系和EJBCA的一些概念

    最近一段时间的在公司做的事情是: 1. 为公司的一些线上系统启用https(使用nginx反向代理的方式来实现,之前的应用无需做改动) 2.为符合规则的用户颁发数字证书(自建CA来实现,目前的用途是给 ...

  2. 关于windows 7系统下开启休眠功能的方法

    今天笔者新装了一个windows 7操作系统,装完后,点击开始按钮.鼠标放到关机处的左边扩展选项时,没有发现休眠选项. 于是开始上网查询解决方法,并将过程记录如下: 首先简单的介绍一下休眠功能:休眠( ...

  3. MVC4.0 IIS 7.5 详细错误 - 404.0 - Not Found

    出现环境:win7 + IIS7.5 问题如下: 1.IIS的根节点->右侧“ISAPI和CGI限制”->把禁止的DotNet版本项设置为允许 如果不行就进行下一步 2.选择站点-> ...

  4. tomcat如何配置context的docBase

    docbase是web应用和本地路径,path是tomcat访问这个应用的URL路径.Tomcat的项目部署方式有以下三种:1.直接把项目复制到Tomcat安装目录的webapps目录中,这是最简单的 ...

  5. 【AngularJs-模块篇-Form篇】

    1.模块 <!doctype html> <html lang="en-US" ng-app="myApp"> <head> ...

  6. win10中强制vs2015使用管理员启动

    文章转自: win10中强制vs2015使用管理员启动   首先,和网上流传的版本一样,需要做这下面这两步: 1. 打开VS快捷方式的属性对话框.   2.勾选“用管理员身份运行”   现在,你双击V ...

  7. mysql数据库恢复

    数据库恢复注意事项: # 数据恢复和字符集关联很大,如果字符集不正确会导致恢复的数据乱码. #MySQL命令和source命令恢复数据库的原理就是把文件的SQL语句,在数据库重新执行的过程. 1.利用 ...

  8. opencv学习笔记霍夫变换——直线检测

    参考大佬博文:blog.csdn.net/jia20003/article/details/7724530 lps-683.iteye.com/blog/2254368 openCV里有两个函数(比较 ...

  9. MySQL在linux上的source code安装方法(configure)

    1.建立操作系统用户和组 [root@faspdev ~]# groupadd mysql [root@faspdev ~]# useradd -g mysql mysql 2.解压安装文件,进入解压 ...

  10. 02 - nginx - 反向代理、限速

    一.Nginx反向代理 代理服务器,客户机在发送请求时,不会直接发送给目的主机,而是先发送给代理服务器. 代理服务接受客户机请求之后,再向主机发出,并接收目的主机返回的数据,存放在代理服务器的硬盘中, ...