问题描述
此问题与this one相同,但适用于本机python列表。
假设以下内容:
import numpy as np
a = np.ones((5,6,7))
a_list = a.tolist()
我可以像这样对a
进行切片:
a_slice = a[2:4,4:,:3]
对于a_list
,是否可以通过某种方式实现?
问的原因是我得到了a_list
之类的嵌套列表流,并且只想保存其中的一部分以供以后使用。
我不想为此使用一个numpy数组,因为它每次都会分配内存,这是次优的。
我正在寻找一种方法来实现这一目标。
编辑shivam_Jha
import numpy as np
a = np.ones((5,7))
a_list = a.tolist()
a_list
Out[20]:
[[[1.0,1.0,1.0],[1.0,1.0]],[[1.0,1.0]]]
期待输出
a[2:4,:3].tolist()
Out[21]: [[[1.0,1.0]]]
解决方法
ALTER TABLE test.t1_euro RENAME COLUMN t1_euro TO t1;
,
也许这就是您想要的:
localhost:3000/dishes/0/comments
输出:
localhost:3000/dishes/0?comments
如果您这样做:
listD = [
[
[
[53,54],[129,130]
]
],[
[
[51,51],[132,132]
]
],[
[
[39,39],[144,144]
],[
[53,[146,146]
],[
[54,[130,[
[
[54,53],129]
]
],[
[
[52,52],132]
]
]
]
newList = [[item[0]] for sub_list in listD for item in sub_list]
print(newList)
它给了我:
[[[53,54]],[[51,51]],[[39,39]],[[53,[[54,53]],[[52,52]]]