首页 » Archive by category 'Python'
Jupyter自动计算每个cell的运行时间
vForce | Python | 2018-05-29
使用jupyter时,经常会想知道这个cell执行了多少时间。每次单独写计时又特别麻烦。gluon介绍了一种方便快捷的方案,通过jupyter_contrib_nbextensions中的计时插件来实现。
pip install jupyter_contrib_nbextensions
jupyter contrib nbextension install --user
jupyter nbextension enable execute_time/ExecuteTime
[阅读全文]
制作pip离线镜像源
总体分为两部分:
1、生成requirement.txt
2、使用脚本下载离线包
这里使用一个简单的PHP脚本自动生成requirement.txt
<?php
$raw_html = file_get_contents("http://mirrors.aliyun.com/pypi/simple/");
$matches = [];
preg_match_all("/<a.*>(.*)<\/a><br\/>/", $raw_html, $matches);... [阅读全文]
Python下在多显卡机器上指定Tensorflow使用哪几块设备
以下代码指定使用0号和1号显卡,分配70%的显存。实际使用时请根据显卡的互相连接情况调整设备号
import os
import tensorflow as tf
from keras.backend.tensorflow_backend import set_session
os.environ["CUDA_VISIBLE_DEVICES"] = '0, 1'
config = tf.ConfigProto()
config.gpu_options.allocator_type = 'BFC' ... [阅读全文]
Python2输出Unicode字符串数组
vForce | Python | 2017-06-22
相信很多朋友在用Python2的时候都会诟病它的编码问题,Unocode字符串的输出一直是个大问题。尽管Python3已经很好地解决了这个问题,但由于很多库依然不支持Python3,所以很多时候还是被迫要使用Python2。
今天碰到的场景就是要输出一个Unicode字符串的数组。通常来说,直接print这个数组会得到的输出会是如下:
[u’\u5de6\u4e3b\u5e72′]
这... [阅读全文]