我需要在Python的切片表示法上有一个很好的解释(引用是一个加号).
对我来说,这种符号需要一点点提升.
它看起来非常强大,但我还没有完全了解它.
我已经改变了一些使用列表来使用双端队列的代码.当我收到错误时,我无法再切入它:
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'
那么,有没有一种解决方法来支持在Python中切割成deques?
我正在运行许多线程并在队列中收集结果.我想将其转储到数组或列表中,以便我可以进行索引并检索这些结果.队列中的每个元素都是维度为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_)
因此,数组是学习的模型参数svm.model_queue在线程之间共享.我想访问每个模型参数向量而不是模型参数的每个条目.