Python:将数组附加到基于字典的新数组

2024-04-26 03:18:02 发布

您现在位置:Python中文网/ 问答频道 /正文

例如,my clusters具有以下功能:

cluster = {0: [array([ 0.66979552,  0.25469174])],
 1: [array([-0.69608797,  0.91087328])]}.

我想把X[j]加到dic(0)后面。假设X[j]是。你知道吗

X[j] = array([ 0.83563669, -0.33302472])

我使用了append函数

cluster[0].append(X[j])

因为这样做而犯了错误。你知道吗

所以,请帮助,我怎样才能附加一个数组到一个基于特定字典的新数组。你知道吗


Tags: 函数功能字典my错误数组arrayclusters
2条回答

我不明白你想说什么。但是,我做到了:

$Python

>>> cluster = {0: [ 0.66979552,  0.25469174],1: [-0.69608797,  0.91087328]}
>>> j = 3
>>> X={}
>>> X[j] = [ 0.83563669, -0.33302472]
>>> cluster[0].append(X[j])
>>> cluster
{0: [0.66979552, 0.25469174, [0.83563669, -0.33302472]], 1: [-0.69608797, 0.91087328]}

这是:

cluster = {0: [[ 0.66979552,  0.25469174]],
 1: [[-0.69608797,  0.91087328]]}

x =[0.83563669, -0.33302472]

cluster[0].append(x)

提供:

{0: [[0.66979552, 0.25469174], [0.83563669, -0.33302472]],
 1: [[-0.69608797, 0.91087328]]}

删除“数组”参数。你知道吗

相关问题 更多 >