我已经使用了一些jQuery UI可排序的插件,但我总是发现同样的问题,我无法在可排序的DIV中选择或点击,所以,也许我可以通过放置一个图标来找到解决方案,你只能拖动div所以你可以选择其他部分.
怎么做?
从今天开始,我得到了很多
警告conda.gateways.disk:exp_backoff_fn(47):使用errno 41进行未检出的退避
我尝试使用conda install或更新或安装软件包时发出警告conda update.例如:
(...) C:\Users\...> conda install numba
Fetching package metadata ...........
Solving package specifications: .
Package plan for installation in environment C:\...:
The following packages will be DOWNGRADED due to dependency conflicts:
numba: 0.30.0-np111py35_0 --> 0.30.1-np111py35_0
Proceed ([y]/n)? y
numba-0.30.0-np111p35_0 100% |###############################| Time: 0:00:00 2.50 MB/s
WARNING conda.gateways.disk:exp_backoff_fn(47): Uncaught backoff with errno 41
WARNING conda.gateways.disk:exp_backoff_fn(47): Uncaught backoff with errno 41
WARNING conda.gateways.disk:exp_backoff_fn(47): Uncaught backoff with errno 41
WARNING conda.gateways.disk:exp_backoff_fn(47): Uncaught backoff with …Run Code Online (Sandbox Code Playgroud) 我很难调试一个问题,在这个问题中,nana list和nana numpy.array中的float 在处理时使用的方式不同itertools.groupby:
给出以下列表和数组:
from itertools import groupby
import numpy as np
lst = [np.nan, np.nan, np.nan, 0.16, 1, 0.16, 0.9999, 0.0001, 0.16, 0.101, np.nan, 0.16]
arr = np.array(lst)
Run Code Online (Sandbox Code Playgroud)
当我遍历列表时,连续的nans被分组:
>>> for key, group in groupby(lst):
... if np.isnan(key):
... print(key, list(group), type(key))
nan [nan, nan, nan] <class 'float'>
nan [nan] <class 'float'>
Run Code Online (Sandbox Code Playgroud)
但是,如果我使用数组,它会将连续的nans放在不同的组中:
>>> for key, group in groupby(arr):
... if np.isnan(key):
... print(key, list(group), type(key)) …Run Code Online (Sandbox Code Playgroud) 我有一个简单的类,可以帮助对向量进行数学运算(即数字列表).我Vector可以乘以其他实例Vector 或标量(float或int).
在其他更强类型的语言中,我将创建一个方法来将两个vectors和一个单独的方法相乘以乘以vector和int/ float.我仍然是Python的新手,我不确定如何实现它.我能想到的唯一方法是覆盖__mul__()并测试传入的参数:
class Vector(object):
...
def __mul__(self, rhs):
if isinstance(rhs, Vector):
...
if isinstance(rhs, int) or isinstance(rhs, float):
...
Run Code Online (Sandbox Code Playgroud)
即使我这样做,我也会被迫乘以这样Vector的标量:
v = Vector([1,2,3])
result = v * 7
Run Code Online (Sandbox Code Playgroud)
如果我想在乘法中颠倒操作数的顺序怎么办?
result = 7 * v
Run Code Online (Sandbox Code Playgroud)
在Python中这样做的正确方法是什么?
在上一个问题中,我问过多处理,使用多个内核使程序运行得更快,有人告诉我:
通常情况下,使用更好的代码可以获得100x +优化,而使用多处理可以获得4倍的改进和额外的复杂性
然后他们建议我应该:
使用分析器来了解什么是慢,然后专注于优化.
所以我回答了这个问题:你如何描述一个脚本?
在这里,我发现cProfile并将其实现到一些测试代码中,以了解它是如何工作的.
这是我的代码:
import cProfile
def foo():
for i in range(10000):
a = i**i
if i % 1000 == 0:
print(i)
cProfile.run('foo()')
Run Code Online (Sandbox Code Playgroud)
然而,在运行之后,这就是我得到的:
0
1000
2000
3000
4000
5000
6000
7000
8000
9000
1018 function calls in 20.773 seconds
Ordered by: standard name
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 20.773 20.773 <string>:1(<module>)
147 0.000 0.000 0.000 0.000 rpc.py:150(debug)
21 0.000 0.000 0.050 0.002 rpc.py:213(remotecall)
21 0.000 0.000 0.002 0.000 …Run Code Online (Sandbox Code Playgroud) python performance profiling processing-efficiency python-3.x
Cython 文档很好地解释了它们允许的内容,如何声明它们以及如何使用它们.
但是,我仍然不清楚他们到底是什么.例如,来自numpy数组的简单赋值如下:
my_arr = np.empty(10, np.int32)
cdef int [:] new_arr = my_arr
Run Code Online (Sandbox Code Playgroud)
可以使访问/分配my_arr更快.
幕后发生了什么?Numpy应该已经以连续的方式在内存中分配元素了,那么内存视图的处理是什么?显然不是那么多,实际上numpy数组的memoryview赋值new_arr应该相当于
cdef np.ndarray[np.int32_t, ndim=1] new_arr = np.empty(10, np.int32)
Run Code Online (Sandbox Code Playgroud)
在速度方面.但是,内存视图被认为比numpy数组缓冲区更通用; 你能举一个简单的例子,其中添加的"概括"是重要/有趣的吗?
此外,如果我已经分配了一个指针以使事情尽可能快,那么将它转换为类型化的内存视图有什么好处?(这个问题的答案可能与上面的问题相同)
cdef int *my_arr = <int *> malloc(N * sizeof(int))
cdef int[:] new_arr = <int[:N]>my_arr
Run Code Online (Sandbox Code Playgroud) 我正在使用numbas @jit装饰器在python中添加两个numpy数组.如果我使用@jit相比,性能是如此之高python.
但是,即使我传入,也没有使用所有CPU内核@numba.jit(nopython = True, parallel = True, nogil = True).
有没有办法利用numba的所有CPU内核@jit.
这是我的代码:
import time
import numpy as np
import numba
SIZE = 2147483648 * 6
a = np.full(SIZE, 1, dtype = np.int32)
b = np.full(SIZE, 1, dtype = np.int32)
c = np.ndarray(SIZE, dtype = np.int32)
@numba.jit(nopython = True, parallel = True, nogil = True)
def add(a, b, c):
for i in range(SIZE):
c[i] = a[i] + b[i]
start = …Run Code Online (Sandbox Code Playgroud) 我找到:
>>> a={'x':42, 'y':3.14, 'z':7}
>>> b=a.__iter__()
>>> b.__dir__()
['__next__', ..., '__iter__', ...]
>>> b
<set_iterator object at 0x7efdd4e5afc0>
Run Code Online (Sandbox Code Playgroud)
迭代器是否总是有__iter__方法?
根据/sf/answers/691898161/,迭代器也是可迭代的.如果迭代器总是有__iter__方法是真的吗?
我正在尝试解决Rosalind在给定序列中计算核苷酸的基本问题,并将结果返回到列表中.对于那些不熟悉生物信息学的人来说,它只计算一个字符串中4个不同字符('A','C','G','T')的出现次数.
我希望collections.Counter这是最快的方法(首先是因为他们声称是高性能,第二是因为我看到很多人使用它来解决这个特定的问题).
但令我惊讶的是这种方法最慢!
我比较了三种不同的方法,使用timeit和运行两种类型的实验:
这是我的代码:
import timeit
from collections import Counter
# Method1: using count
def method1(seq):
return [seq.count('A'), seq.count('C'), seq.count('G'), seq.count('T')]
# method 2: using a loop
def method2(seq):
r = [0, 0, 0, 0]
for i in seq:
if i == 'A':
r[0] += 1
elif i == 'C':
r[1] += 1
elif i == 'G':
r[2] += 1
else:
r[3] += 1
return r
# method 3: using Collections.counter …Run Code Online (Sandbox Code Playgroud) 目前,当我更新软件包时,我收到了很多这些INFO消息:
$ conda update --all --yes
Fetching package metadata .................
Solving package specifications: .
Package plan for installation in environment C:\anacondadir:
The following packages will be UPDATED:
ipython: 6.0.0-py35_1 --> 6.1.0-py35_0
nbconvert: 5.1.1-py35_0 --> 5.2.1-py35_0
testpath: 0.3-py35_0 --> 0.3.1-py35_0
testpath-0.3.1 100% |###############################| Time: 0:00:00 1.31 MB/s
ipython-6.1.0- 100% |###############################| Time: 0:00:00 2.77 MB/s
nbconvert-5.2. 100% |###############################| Time: 0:00:00 3.36 MB/s
INFO menuinst_win32:__init__(182): Menu: name: 'Anaconda${PY_VER} ${PLATFORM}', prefix: 'C:\anacondadir', env_name: 'None', mode: 'None', used_mode: 'user'
INFO menuinst_win32:__init__(182): Menu: name: 'Anaconda${PY_VER} ${PLATFORM}', …Run Code Online (Sandbox Code Playgroud) python ×9
arrays ×2
conda ×2
numpy ×2
performance ×2
python-3.x ×2
class ×1
collections ×1
counter ×1
cython ×1
iterable ×1
iterator ×1
javascript ×1
jit ×1
jquery-ui ×1
list ×1
logging ×1
memoryview ×1
methods ×1
multicore ×1
nan ×1
numba ×1
operators ×1
profiling ×1
warnings ×1