相关疑难解决方法(0)

了解切片表示法

我需要在Python的切片表示法上有一个很好的解释(引用是一个加号).

对我来说,这种符号需要一点点提升.

它看起来非常强大,但我还没有完全了解它.

python iterable list slice

3024
推荐指数
33
解决办法
159万
查看次数

如何切一个双端队列?

我已经改变了一些使用列表来使用双端队列的代码.当我收到错误时,我无法再切入它:

TypeError:序列索引必须是整数,而不是'slice'

这是一个显示问题的REPL.

>>> import collections
>>> d = collections.deque()
>>> for i in range(3):
...     d.append(i)
...
>>> d
deque([0, 1, 2])
>>> d[2:]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: sequence index must be integer, not 'slice'
Run Code Online (Sandbox Code Playgroud)

那么,有没有一种解决方法来支持在Python中切割成deques?

python deque slice

24
推荐指数
2
解决办法
1万
查看次数

将队列转储到python中的列表/数组中

我正在运行许多线程并在队列中收集结果.我想将其转储到数组或列表中,以便我可以进行索引并检索这些结果.队列中的每个元素都是维度为n的数组.我想访问这些数组.请你告诉我,我怎么办?

 def dump_queue(model_queue):
 queue_list = []
 for i in iter(model_queue.get,'STOP'):
         queue_list.append(i)
  return queue_list




aux_model=train_svm(np.array(trainExample),np.array(trainLabel))
model_queue.put(aux_model.coef_)
Run Code Online (Sandbox Code Playgroud)

因此,数组是学习的模型参数svm.model_queue在线程之间共享.我想访问每个模型参数向量而不是模型参数的每个条目.

python queue deque

10
推荐指数
3
解决办法
3万
查看次数

标签 统计

python ×3

deque ×2

slice ×2

iterable ×1

list ×1

queue ×1