我使用IPython笔记本,并希望能够选择在IPython中创建2.x或3.x python笔记本.
我最初有Anaconda.使用Anaconda时,必须更改全局环境变量以选择所需的python版本,然后才能启动IPython.这不是我想要的,所以我卸载了Anaconda,现在已经使用MacPorts和PiP设置了我自己的安装.看来我还是要用
port select --set python <python version>
Run Code Online (Sandbox Code Playgroud)
在python 2.x和3.x之间切换.这并不比蟒蛇解决方案好.
有没有办法在启动IPython笔记本后选择要使用的python版本,最好是使用我当前的MacPorts构建?
我有一个包含时间序列数据的numpy数组.我想将该数组分成给定长度的相等分区(如果它的大小不同,可以删除最后一个分区),然后计算每个分区的平均值.
我怀疑有这样的numpy,scipy或pandas功能.
例:
data = [4,2,5,6,7,5,4,3,5,7]
Run Code Online (Sandbox Code Playgroud)
对于bin大小为2:
bin_data = [(4,2),(5,6),(7,5),(4,3),(5,7)]
bin_data_mean = [3,5.5,6,3.5,6]
Run Code Online (Sandbox Code Playgroud)
对于bin大小为3:
bin_data = [(4,2,5),(6,7,5),(4,3,5)]
bin_data_mean = [7.67,6,4]
Run Code Online (Sandbox Code Playgroud) 我刚刚安装了CUDA并且一直关注http://docs.nvidia.com/cuda/cuda-getting-started-guide-for-mac-os-x/index.html
一切正常,直到我尝试将示例代码(如deviceQuery)复制到〜/ Desktop并编译.
我在编译时遇到以下错误:
/Developer/NVIDIA/CUDA-5.5/bin/nvcc -ccbin g++ -I../../common/inc -m64 -Xcompiler -arch -Xcompiler x86_64 -gencode arch=compute_10,code=sm_10 -gencode arch=compute_20,code=sm_20 -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=\"sm_35,compute_35\" -o deviceQuery.o -c deviceQuery.cpp
deviceQuery.cpp:23:25: error: helper_cuda.h: No such file or directory
deviceQuery.cpp: In function ‘int main(int, char**)’:
deviceQuery.cpp:111: error: ‘SPRINTF’ was not declared in this scope
deviceQuery.cpp:116: error: ‘_ConvertSMVer2Cores’ was not declared in this scope
deviceQuery.cpp:206: error: ‘checkCudaErrors’ was not declared in this scope
deviceQuery.cpp:230: error: ‘checkCudaErrors’ was not declared in this scope
deviceQuery.cpp:241: error: ‘checkCudaErrors’ was …Run Code Online (Sandbox Code Playgroud) 我必须读取和解析太大而无法加载到内存中的 .pcap 文件。我目前在离线模式下使用嗅探
sniff(offline=file_in, prn=customAction, store=0)
Run Code Online (Sandbox Code Playgroud)
使用 customAction 函数,大致如下所示:
customAction(packet):
global COUNT
COUNT = COUNT + 1
# do some other stuff that takes practically 0 time
Run Code Online (Sandbox Code Playgroud)
目前,这处理数据包的速度太慢。我已经在“驱动程序”程序中使用子进程在不同内核上同时在多个文件上运行此脚本,但我确实需要提高单核性能。
我尝试使用 pypy,但感到失望的是,使用 pypy 的性能比使用 python3 (anaconda) 的性能好不到 10%。
使用 pypy 运行 50k 数据包的平均时间为 52.54 秒
使用 python3 运行 50k 数据包的平均时间为 56.93 秒
有什么办法可以加快速度吗?
编辑:下面是 cProfile 的结果,您可以看到代码在分析时有点慢,但所有时间都花在 scapy 上。
66054791 function calls (61851423 primitive calls) in 85.482 seconds
Ordered by: cumulative time
ncalls tottime percall cumtime percall filename:lineno(function)
957/1 0.017 0.000 85.483 85.483 …Run Code Online (Sandbox Code Playgroud) 我有一个带有交互式绘图的Jupyter笔记本。我正在使用将笔记本转换成幻灯片nbconvert。当我这样做时,在幻灯片中不会显示密谋图。我也收到以下龙卷风警告
$ jupyter nbconvert presentation.ipynb --to slides --post serve
[NbConvertApp] Converting notebook presentation.ipynb to slides
[NbConvertApp] Writing 818538 bytes to presentation.slides.html
[NbConvertApp] Redirecting reveal.js requests to https://cdnjs.cloudflare.com/ajax/libs/reveal.js/3.1.0
Serving your slides at http://127.0.0.1:8000/presentation.slides.html
Use Control-C to stop this server
WARNING:tornado.access:404 GET /custom.css (127.0.0.1) 1.53ms
WARNING:tornado.access:404 GET /custom.css (127.0.0.1) 0.96ms
WARNING:tornado.access:404 GET /plotly.js (127.0.0.1) 0.84ms
Run Code Online (Sandbox Code Playgroud)
昨天,这种侮辱增加了伤害,我认为我并没有做出任何重大改变。我尝试重新启动浏览器和计算机,但均无济于事。
我在数据框中有时间序列数据,如下所示:
Index Time Value_A Value_B
0 1 A A
1 2 A A
2 2 B A
3 3 A A
4 5 A A
Run Code Online (Sandbox Code Playgroud)
我想删除Value_A和Value_B列中的副本,以便仅在遇到不同的模式时才删除重复项.此示例数据的结果应为:
Index Time Value_A Value_B
0 1 A A
2 2 B A
3 3 A A
Run Code Online (Sandbox Code Playgroud) 我需要取一个像 0.405 这样的数字并将其四舍五入为 0.40,同时还将 0.412 四舍五入为 0.42。有没有内置函数可以做到这一点?
我有一个pandas数据框,从具有以下结构的.csv文件读入:
Date, Latitude, Longitude, Brand, Pump, AKI, Trip Miles, Total Miles, Gallons, MPG, PPG, Total, Tires, MPG-D,
11/03/2013, 40° 1.729', -105° 15.516', Boulder Gas, 2, 87, 134.3, 134.3, 6.563, 20.46, 3.319, 21.78, Stock, ,
11/17/2013, 40° 1.729', -105° 15.516', Boulder Gas, 2, 87, 161.8, 296.0, 7.467, 21.67, 3.279, 24.48, Stock, ,
11/27/2013, 40° 0.872', -105° 12.775', Buffalo Gas, 6, 87, 180.8, 477.0, 8.096, 22.33, 3.359, 27.19, Stock, ,
12/07/2013, 40° 1.729', -105° 15.516', Boulder Gas, 6, 87, 265.1, 742.0, 12.073, …Run Code Online (Sandbox Code Playgroud) python ×6
pandas ×3
numpy ×2
python-3.x ×2
scipy ×2
arrays ×1
compilation ×1
cuda ×1
dataframe ×1
ipython ×1
matplotlib ×1
nbconvert ×1
pcap ×1
performance ×1
plot ×1
plotly ×1
presto ×1
pypy ×1
python-2.7 ×1
reveal.js ×1
scapy ×1
time-series ×1