Python编程

来自iCenter Wiki
2019年6月11日 (二) 01:31Zhenchen讨论 | 贡献的版本

跳转至: 导航搜索

理解编程

Programming Program

python语言

集成开发环境IDE

编辑器软件安装:

  • 编辑开发环境
(1)Visual Studio Code/ Notepad++文件编辑器 / Sublime 文本编辑器;
(2)Git-bash安装程序;


Python安装

Python 3.6.2+。

Python安装程序可以从Python网站(http://www.python.org)直接下载,或者也可以直接安装Anacoda Python发行版(https://www.continuum.io)。

pip安装python包

大多数Python 包都使用pip 实用工具安装。

$ pip install flask

手动安装pip,安装方法参见pip 的网站: https://pip.pypa.io/en/latest/installing/

文件读取:csv(pandas库),图片(pilllow库),其他(字符串处理)

Pandas库使用

#/usr/bin/python
# -*- coding: utf-8 -*-
import pandas as np
import sys
df = np.read_csv("traffic.txt", header=None)
for x in range(0,10):
	df.to_csv("%d.csv" %x, columns=[x], header=True, index=False)

Numpy库使用

Numpy数据操作:基本操作(dtype,reshape,transpose),数据切分(下标访问,random.sample等等)

以下代码绘制sin(x)/x函数:

import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(-10,10,1000)
sink = lambda x: np.sin(x)/x
plt.plot(x, sink(x), color='blue', lw=2)
plt.show()

参考书

  1. Stanford U., CS231n, http://cs231n.github.io/python-numpy-tutorial/.
  2. ICML-2017 TensorFlow workshop, https://github.com/random-forests/tensorflow-workshop/.
  3. Lutz, Mark. Learning python. " O'Reilly Media, Inc.", 2013.