小编Jus*_*gan的帖子

在matplotlib/seaborn图中的某些单元格中添加自定义边框

现在我正在使用Seaborn的集群图生成一些集群热图 - 到目前为止一切都很好.

对于某个用例,我需要在特定单元格周围绘制彩色边框.有没有办法做到这一点?或者使用matplotlib中的pcolormesh或任何其他方式?

python matplotlib seaborn

12
推荐指数
1
解决办法
3348
查看次数

Python Line_profiler和Cython函数

所以我试图在我自己使用的python脚本中分析一个函数line_profiler,因为我想要逐行时序.唯一的问题是该函数是一个Cython函数,并且line_profiler无法正常工作.在第一次运行时,它只是崩溃了一个错误.然后我补充道

!python
cython: profile=True
cython: linetrace=True
cython: binding=True
Run Code Online (Sandbox Code Playgroud)

在我的脚本的顶部,现在运行正常,除了时间和统计是空白的!

有没有办法使用line_profilerCythonized函数?

我可以分析非Cythonized函数,但它比Cythonized函数慢得多,我无法使用来自分析的信息 - 纯python的慢速将使我无法改进Cython的一个.

这是我想要分析的函数的代码:

class motif_hit(object):
__slots__ = ['position', 'strand']

def __init__(self, int position=0, int strand=0):
    self.position = position
    self.strand = strand

#the decorator for line_profiler
@profile
def find_motifs_cython(list bed_list, list matrices=None, int limit=0, int mut=0):
    cdef int q = 3
    cdef list bg = [0.25, 0.25, 0.25, 0.25]
    cdef int matrices_length = len(matrices)
    cdef int results_length = 0
    cdef int results_length_shuffled = 0 …
Run Code Online (Sandbox Code Playgroud)

python profiling cython

9
推荐指数
2
解决办法
3136
查看次数

Cythonize两个小numpy函数,帮助需要

问题

我正在尝试Cythonize两个小函数,主要处理numpy ndarray用于某些科学目的.这两个小函数在遗传算法中被称为数百万次,占算法占用的大部分时间.

我自己取得了一些进展并且都很好地工作,但我只获得了很小的速度提升(10%).更重要的是,cython --annotate表明大多数代码仍然通过Python.

代码

第一个功能:

此函数的目的是获取数据切片,并在内部嵌套循环中调用数百万次.根据数据[1] [1]中的bool,我们要么以正序或反向顺序得到切片.

#Ipython notebook magic for cython
%%cython --annotate
import numpy as np
from scipy import signal as scisignal

cimport cython
cimport numpy as np
def get_signal(data):
    #data[0] contains the data structure containing the numpy arrays
    #data[1][0] contains the position to slice
    #data[1][1] contains the orientation to slice, forward = 0, reverse = 1

    cdef int halfwinwidth = 100
    cdef int midpoint = data[1][0]
    cdef int strand = data[1][1]
    cdef int start = …
Run Code Online (Sandbox Code Playgroud)

python arrays numpy cython memoryview

5
推荐指数
1
解决办法
575
查看次数

标签 统计

python ×3

cython ×2

arrays ×1

matplotlib ×1

memoryview ×1

numpy ×1

profiling ×1

seaborn ×1