【发布时间】:2021-03-23 15:52:10
【问题描述】:
给定一个列表标签
Label=np.empty((2,1), dtype=object) # array([[None], [None]], dtype=object)
#first row should be like this;
Label[0][0] = [Label[0][0], 1] # output array([[list([1])], [None]], dtype=object)
Label[0][0] = [Label[0][0], 3] # output array([[list([1,3])], [None]], dtype=object)
#the second row
Label[1][0] = [Label[1][0], 2] # output array([[list([1,3])], [list([2])]], dtype=object)
Label[1][0] = [Label[1][0], 4] # output array([[list([1,3])],[list([2,4])]], dtype=object)
我尝试了以下方法。
#1.
Label[0][0] = [a + b for (a, b) in zip([Label[0][0]], [1])]
#I got an error -> TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'
#2.
Label[0][0] = [Label[0][0],1] #It gives a list with a different structure
非常感谢您的帮助。
【问题讨论】:
标签: python python-3.x list