0%

Numpy 和原生 Python list 性能对比

1
2
3
4
5
def numpy_sum (n):
a = np.arange (n) ** 2
b = np.arange (n) ** 3
return a+b
// 调用函数后输出:array ([ 0, 2, 12, 36, 80, 150, 252, 392, 576, 810], dtype=int32)
閱讀全文 »

常見的深度學習架構,如多層感知器 (Multilayer Perceptron)、深度神經網路 DNN (Deep Neural Network)、卷積神經網路 CNN (Convolutional Neural Network)、遞迴神經網路 RNN (Recurrent Neural Network)。

一、Deep Learning

1.Neural Network

Fully Connect Feedforward Network
neural network 中神經元的函數稱爲 activation function(通常是非線性的),不一定要是 signoid
-> Matrix Operation
-> 普通的 GPU 加速就是利用并行方式進行矩陣運算

閱讀全文 »

一、使用 Pandas 的好处

方便和 Python 其他类库一起使用
numpy:用于数学计算
scikit-learn:用于机器学习

二、Pandas 读取数据

1. 读取方式

pd.read_csv
pd.read_excel
pd.read_sql

三、Pandas 数据结构:Dataframe 和 Series

安装步骤

1. 安装 Anaconda

2. 打开 Anaconda-Navigator

更改 Anaconda 的服务为国内镜像,提高下载速度(选做)
channel - add - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// 在 Anaconda Prompt,创建一个 python3.6 的环境,环境名称为 tensorflow
conda create -n tensorflow python=3.6
// 在 Anacoda Prompt 下启动 tensorflow 环境
// 安装 cpu 版本的 TensorFlow
pip install --upgrade --ignore-installed tensorflow
activate tensorflow
// 测试(Session () 是 tensorflow1 的函数)
>>> import tensorflow as tf
>>> hello = tf.constant ('Hello, TensorFlow!')
>>> sess = tf.Session ()
>>> print (sess.run (hello))
b'Hello, TensorFlow!'
>>> sess.close ()
// 测试
>>> import tensorflow as tf
>>> a = tf.constant (2.0)
>>> b = tf.constant (4.0)
>>> print (a + b)

3. 安装 tensorflow

4. 在 pycharm 中使用 tensorflow

打开 Pycharm,点击 “file” 菜单下的 settings
Project:Pycharm - Project Interpreter
点击右侧的小三角下的 “Add” 按钮,添加安装 Anaconda-TensorFlow 下的 python.exe
(Anaconda、TensorFlow 安装和 Pycharm 配置详细教程)[https://zhuanlan.zhihu.com/p/77494679]

5. 在 ipython notebook 中使用 tensorflow

在虚拟环境中(tensorflow_env)安装 jupyter,在 cmd 中执行以下命令:

1
2
3
4
5
conda activate tensorflow_env // 激活环境 TensorFlow
conda install ipython // 安装 ipython
conda install jupyter // 安装 jupyter
ipython kernelspec install-self --user // 安装 python kernel for Tensroflow
jupyter notebook // 验证,看是否自动跳转到 tensorflow 虚拟环境下的 jupyter 网页

5.Anaconda 快捷键

Shift + enter -> 执行这个 cell
Esc+a (esc 是从 Edit Mode 跳回 Command Mode 的意思) -> a 是 above 的意思,在现有的 cell 上方新增一个 cell
Esc+b -> b 是 below 的意思,在现有的 cell 下方新增一个 cell
Esc+h-> h 是 help 的意思,能列出所有的快捷键

问题

1.The TensorFlow library wasn’t compiled to use SSE instructions,

but these are available on your machine and could speed up CPU computations.

遇到这个警告的原因是,你是使用例如 “pip install tensorflow” 这种方法安装的 Tensorflow,而不是从源码编译安装的。
这只是个警告,只是影响 cpu 计算速度而已。使用或者不使用 SSE 你的程序都是可以运行的。
此外,如果你是使用的 gpu 版本,在 gpu 上的运行是不受 SSE 影响的。

解决方法:在开始时加上

1
2
import os
os.environ ['TF_CPP_MIN_LOG_LEVEL']='2'

2.Tensorflow 版本问题

Tensorflow has no attribute ‘Session‘错误原因

3.jupyter 无法连接 python 服务

解决 jupyter—notebook 无法连接 python 服务(无法连接内核),显示一直 IN [*]

深度学习系列

深度学习 —(1)环境配置:Anaconda + Tensorflow

一、变量

1. 基本使用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 输入苹果单价
price_str = input ("请输入苹果价格:")

# 输入苹果重量
weight_str = input ("请输入苹果重量:")

# 计算金额
price = float (price_str) # 将苹果单价转换成小数
weight = float (weight_str) # 将苹果重量转换成小数

# 计算付款金额
money = price * weight

print (money)
閱讀全文 »