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 math
package 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 ...
随机推荐
- 以太网端口二种链路类型:Access 和Trunk
Access 类型的端口:只能属于1 个VLAN,一般用于连接计算机的端口: Trunk 类型的端口:可以允许多个VLAN 通过,可以接收和发送多个VLAN 的报文,一般用于交换机之间连接的端口 ...
- 【Servlet】关于RequestDispatcher的原理
RequestDispatcher简介 RequestDispatcher 代表请求的派发者.它有2个动作:forward 和 include .客户端对于任何一个请求,可以根据业务逻辑需要,选择不同 ...
- 【C#】简单计算器源代码
form1.cs using System; using System.Collections.Generic; using System.ComponentModel; using System.D ...
- iOS - APP审核Guideline 2.5.1被拒,使用了私有API
最近iOS 审核被拒,说是使用了私有API:com.apple.springboard.lockcomplete 具体内容如下: 发件人 Apple . Performance: Software R ...
- thinkphp自动验证详解
自动验证时THINKPHP提供的一种比较好的验证方式,可以在使用create创建数据对象的时候自动进行数据验证. 数据进行自动验证的方式有两种: 1.静态方式:在模型类里面通过$_validate属性 ...
- DevOps工具链
Devops工具链 DevOps实际是一种文化上的变迁,代表了开发.运维.测试等环节之间的协作,因此DevOps工具是非常多种多样的,甚至可以由多种工具组成一个完整的DevOps工具链.此类工具可以应 ...
- ASP.NET Web配置指南
利用ASP.NET,可以指定影响服务器上所有的Web应用程序.仅影响单个的应用程序.影响个别页面.或影响Web应用程序中的个别文件夹的配置设置.可以对编译器选项.调试.用户身份验证.错误消息显示.连接 ...
- Solr学习笔记之4、Solr配置文件简介
Solr学习笔记之4.Solr配置文件简介 摘自<Solr in Action>. 1. solr.xml – Defines one or more cores per Solr ser ...
- IDA的头像
Ada Lovelace,世界第一位女programmer,为Charles Babbage 做了不少工作,IDA 用她的头像作为图标是为了纪念这位女程序员.Wikipedia上有一幅她的很漂亮的画像 ...
- 2018/03/11 每日一个Linux命令 之 top
每日一个Linux命令 之 top 今天在公司测试服务器上跑了一个我写的功能[本地测试过的],但是不知道怎么跑了个无限死循环出来,一个文件的体积在不停的变大,如果不管的话这能行? 上去一看,PHP ...