尝试在python中使用hstack时出错

时间:2018-10-29 02:46:15

标签: python scipy

当我尝试使用hstack时,我想知道错误的原因是什么。我尝试了许多不同的更改,但找不到引发错误的问题的原因。

from scipy.sparse import hstack, vstack

aa = []

# the below is the output when I print my vectors from word2vec when I print it
a = [[-0.03014902 -0.01852346  0.06285909  0.02631802  0.09288044]
 [-0.00310899  0.07737375  0.03548344  0.05210504  0.07760715]
 [ 0.02859818  0.07507176 -0.05113295  0.09960072 -0.01029834]
 [ 0.04288696  0.05407713  0.08542829 -0.07381271  0.05707014]
 [ 0.08741225 -0.06715555 -0.01421211  0.08771785 -0.03598125]
 [-0.06138502  0.01911862 -0.01389303  0.03253852  0.0871102 ]
 [-0.09148102  0.07785938 -0.04683864  0.09430503 -0.04728664]
 [-0.03338723  0.08450983  0.00142378  0.08840533  0.05170447]]
[[-0.03014902 -0.01852346  0.06285909  0.02631802  0.09288044]
 [ 0.0199983   0.070786   -0.00083511 -0.07408031  0.01747499]
 [ 0.04828767  0.08957508  0.0979019   0.04620161 -0.06655209]
 [ 0.00585169  0.0062088  -0.05540216 -0.09653281  0.07003148]
 [-0.00228108 -0.04216899  0.09433381 -0.05319278 -0.04772797]
 [-0.04499546  0.09941941 -0.07890675 -0.06607837  0.07255891]
 [-0.03338723  0.08450983  0.00142378  0.08840533  0.05170447]]
[[-0.03014902 -0.01852346  0.06285909  0.02631802  0.09288044]
 [-0.00310899  0.07737375  0.03548344  0.05210504  0.07760715]
 [ 0.02859818  0.07507176 -0.05113295  0.09960072 -0.01029834]
 [ 0.04288696  0.05407713  0.08542829 -0.07381271  0.05707014]
 [ 0.08741225 -0.06715555 -0.01421211  0.08771785 -0.03598125]
 [-0.06138502  0.01911862 -0.01389303  0.03253852  0.0871102 ]
 [-0.09148102  0.07785938 -0.04683864  0.09430503 -0.04728664]
 [-0.03338723  0.08450983  0.00142378  0.08840533  0.05170447]]
[[-0.03014902 -0.01852346  0.06285909  0.02631802  0.09288044]
 [ 0.0199983   0.070786   -0.00083511 -0.07408031  0.01747499]
 [ 0.04828767  0.08957508  0.0979019   0.04620161 -0.06655209]
 [ 0.00585169  0.0062088  -0.05540216 -0.09653281  0.07003148]
 [-0.00228108 -0.04216899  0.09433381 -0.05319278 -0.04772797]
 [-0.04499546  0.09941941 -0.07890675 -0.06607837  0.07255891]
 [-0.03338723  0.08450983  0.00142378  0.08840533  0.05170447]]

aa.append(a)

#then it became this for aa:

b = [array([[-0.05161844,  0.09484554, -0.0807794 ,  0.06945045, -0.00778284],
       [-0.05966971, -0.08172162,  0.00020388, -0.02750283,  0.03688101],
       [-0.08569796, -0.05902026, -0.03538166,  0.05673445,  0.06991038],
       [ 0.02022025,  0.00774677,  0.06411666,  0.04324987, -0.0308816 ],
       [-0.07537405,  0.05570554,  0.08752953, -0.06183487,  0.00737487],
       [ 0.08216958,  0.02343195,  0.02489546,  0.09836511, -0.00924806],
       [ 0.0355818 , -0.00691087,  0.04320084, -0.09490094,  0.05833766],
       [-0.03666308, -0.02898009,  0.00580852,  0.09214396,  0.05430224]]), array([[-0.05161844,  0.09484554, -0.0807794 ,  0.06945045, -0.00778284],
       [ 0.05248339,  0.01649389,  0.0692149 , -0.07133561, -0.07755911],
       [ 0.03068119, -0.09182968, -0.04452222, -0.00941208, -0.06595286],
       [-0.01982791,  0.02771765,  0.01573973, -0.01602369, -0.08377324],
       [ 0.0262042 ,  0.08150768, -0.09958926, -0.00704867, -0.08940252],
       [-0.05309275, -0.09251712, -0.04619201,  0.06917179, -0.03696068],
       [-0.03666308, -0.02898009,  0.00580852,  0.09214396,  0.05430224]])]
[array([[-0.05161844,  0.09484554, -0.0807794 ,  0.06945045, -0.00778284],
       [-0.05966971, -0.08172162,  0.00020388, -0.02750283,  0.03688101],
       [-0.08569796, -0.05902026, -0.03538166,  0.05673445,  0.06991038],
       [ 0.02022025,  0.00774677,  0.06411666,  0.04324987, -0.0308816 ],
       [-0.07537405,  0.05570554,  0.08752953, -0.06183487,  0.00737487],
       [ 0.08216958,  0.02343195,  0.02489546,  0.09836511, -0.00924806],
       [ 0.0355818 , -0.00691087,  0.04320084, -0.09490094,  0.05833766],
       [-0.03666308, -0.02898009,  0.00580852,  0.09214396,  0.05430224]]), array([[-0.05161844,  0.09484554, -0.0807794 ,  0.06945045, -0.00778284],
       [ 0.05248339,  0.01649389,  0.0692149 , -0.07133561, -0.07755911],
       [ 0.03068119, -0.09182968, -0.04452222, -0.00941208, -0.06595286],
       [-0.01982791,  0.02771765,  0.01573973, -0.01602369, -0.08377324],
       [ 0.0262042 ,  0.08150768, -0.09958926, -0.00704867, -0.08940252],
       [-0.05309275, -0.09251712, -0.04619201,  0.06917179, -0.03696068],
       [-0.03666308, -0.02898009,  0.00580852,  0.09214396,  0.05430224]])]   

#when I try to use hstack:
check = feature_vectors = [[] for i in range(2)]
for x, xx in enumerate(b):
    check[i].append(xx)


#Here I try to use hstack but received errors
vectors = [hstack(v) for v in check]

错误:

raise ValueError('blocks must be 2-D')

ValueError:块必须为二维

有人说我可以在check [0] [0]中使用vectors = [hstack(v)表示v,但我不想更改这部分。是否有可能改变以前的零件?

0 个答案:

没有答案