Intro to Python for Data Science Learning 5 - Packages
Packages
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的更多相关文章
- 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 ...
- 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- ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- Intermediate Python for Data Science learning 2 - Histograms
Histograms from:https://campus.datacamp.com/courses/intermediate-python-for-data-science/matplotlib? ...
- 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 ...
- Intermediate Python for Data Science learning 3 - Customization
Customization from:https://campus.datacamp.com/courses/intermediate-python-for-data-science/matplotl ...
随机推荐
- 【CF878C】Tournament set+并查集+链表
[CF878C]Tournament 题意:有k个项目,n个运动员,第i个运动员的第j个项目的能力值为aij.一场比赛可以通过如下方式进行: 每次选出2个人和一个项目,该项目能力值高者获胜,败者被淘汰 ...
- [Key] RegCure Pro
Serial RegCure Pro : 4A803-C4F23-422B6-1F3D6 http://www.paretologic.com/product/regcure-pro/
- TFS二次开发08——分支(Branch)和合并(Merge)
一:创建分支 private static void BranchFile(Workspace workspace, String newFilename) { String branchedFi ...
- springMVC + quartz实现定时器(任务调度器)
首先我们要知道任务调度器(定时器)有几种,这边我会写三种 第一种是基于JDK的本身的一个定时器(优点:简单,缺点:满足不了复杂的需求) package com.timer1; import java. ...
- ubuntu16.04下安装sublime_text
1 在终端输入: sudo add-apt-repository ppa:webupd8team/sublime-text-3 添加sublime text3的软件源: 2 sudo apt-get ...
- MyBatis学习(一)一个简单的例子
mybatis入门例子 开发步骤: 1.创建java工程 2.加入jar包(依赖包.驱动包) 3.创建sqlMapConfig.xml 4.创建数据库,数据库表USER_C,插入测试记录 5.创建PO ...
- 双节点weblogic集群安装
一.准备工作 1.环境信息规划 Server name Ip地址 Port 备注 AdminServer 192.168.100.175 7001 管理服务器 Ms1 192.168.100.175 ...
- 实现 TensorFlow 架构的规模性和灵活性
TensorFlow https://mp.weixin.qq.com/s/tEyX596WXTzsABXaeTesug
- HTML_body标签
常用符号:空格:  大于号:> 小于号: < 块级标签:H标签(加大加粗),P标签(段落间有间距),DIV(白板) 行内标签:SPAN标签(白板) <!- ...
- Scala安装配置
注:下载地址:http://downloads.typesafe.com/scala/2.11.6/scala-2.11.6.tgz?_ga=1.41078626.1125902863.1429259 ...