[英]Is there a way to append in a 2d array without numpy?
So, my computer won't load numpy
and I need to append another row to a 2d array with 7 rows. 因此,我的计算机将不会加载
numpy
,我需要将另一行追加到具有7行的2d数组中。 Is there a way to append another row? 有没有办法追加另一行?
I've already tried a.append
but it doesn't work because there are multiple rows. 我已经尝试过
a.append
但是因为有多行,所以它不起作用。
a = ([['Mon', 18, 20, 22, 17],
['Tue', 11, 18, 21, 18],
['Wed', 15, 21, 20, 19],
['Thu', 11, 20, 22, 21],
['Fri', 18, 17, 23, 22],
['Sat', 12, 22, 20, 18],
['Sun', 13, 15, 19, 16]])
for elem in a:
print(elem)
m_r = append(a, [['Avg', 12, 15, 13, 11]], 0)
I want to have another row of [['Avg', 12, 15, 13, 11]], 0)
underneath the rest of my code, but I'm only getting errors. 我想在代码的其余部分下面再加上一行
[['Avg', 12, 15, 13, 11]], 0)
,但我只会遇到错误。
append
should normally work in this case. 在这种情况下,
append
通常应该起作用。 Try: 尝试:
a.append(['Avg', 12, 15, 13, 11])
The problem might be the double bracket [[
. 问题可能出在双括号
[[
。
If I understand correctly, you have a list of lists, which you think of as a "2d array". 如果我理解正确,那么您就有一个列表列表,您将其视为“ 2d数组”。 To add another "row", simply use append, eg
a.append(['Avg', 12, 15, 13, 11])
. 要添加另一个“行”,只需使用append,例如
a.append(['Avg', 12, 15, 13, 11])
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.