AxisError: axis 1 is out of bounds for array of dimension 1 - np.concatenate()
AxisError: axis 1 is out of bounds for array of dimension 1 - np.concatenate()
我想使用以下方法连接两个 Numpy 数组:
np.concatenate((x,y.reshape(len(y),1)),axis=1)
x
array([0.02542383, 0.05432444, 0.05592916, 0.0225309 , 0.05751058,
0.05878261, 0.22347298, 0.32191235, 0.02411838, 0.25474137,
0.04921983, 0.05736983, 0.05435839, 0.01524537, 0.05145499,
0.07242904, 0.0506223 , 0.19234735, 0.05399891, 0.0410024 ,
0.03938462, 0.07316477, 0.01000894, 0.01053533, 0.19936873,
0.41291729, 0.04906247, 0.02723546, 0.01838214, 0.06434103,
0.26908878, 0.10925268, 0.20858194, 0.03522793, 0.04499719,
0.03410352, 0.02554791, 0.09302561, 0.03608627, 0.04368193,
0.0271514 , 0.10271527, 0.07826084, 0.0166053 , 0.13437232,
0.10548925, 0.07658451, 0.02076723, 0.03385754, 0.02455683,
0.04214978, 0.1913195 , 0.02690974, 0.00714601, 0.14730562,
0.09305552, 0.06944146, 0.11340955, 0.10525494, 0.04790132,
0.05222447, 0.07743867, 0.04675769, 0.03493571, 0.0444973 ,
0.09345969, 0.04027045, 0.03830293, 0.06390374, 0.06208764,
0.04554125, 0.01742904, 0.03830261, 0.06413129, 0.02297048,
0.03130876, 0.05521549, 0.14778974, 0.02137831, 0.17142863,
0.03001146, 0.0176135 , 0.02883904, 0.03828 , 0.0202778 ,
0.03461585, 0.12083221, 0.09090906, 0.04827766, 0.09999199,
0.04247083, 0.13864809, 0.05922635, 0.0201329 , 0.04460693,
0.04079322, 0.09750553, 0.0329554 , 0.05622296])
y
array([-0.02264446, 0.02542564, 0.04211922, -0.02332023, 0.00414108,
-0.07603503, 0.21184521, 0.25857056, -0.02607102, 0.23368499,
-0.06407522, 0.03897381, 0.03183766, -0.00508868, -0.0685759 ,
0.02609174, -0.05864956, 0.15634075, -0.05422548, -0.03422613,
-0.03380019, 0.04736571, -0.01302442, 0.00907436, -0.27951327,
0.33882699, -0.06054897, -0.0261247 , -0.01752124, -0.08576588,
-0.38324596, 0.08439715, -0.25341709, -0.02779527, 0.03147691,
0.00644152, -0.02657317, -0.13311193, -0.02792882, -0.05643179,
-0.0334482 , -0.09923616, 0.04261594, -0.01999107, 0.06820104,
-0.13978655, 0.01447225, -0.02443087, -0.02772215, -0.01314321,
0.01165549, 0.04264553, -0.02124456, -0.00884472, -0.0297479 ,
-0.1328692 , 0.05718329, 0.08992262, 0.01722447, -0.05886641,
0.00873129, 0.05607011, -0.04796337, -0.01090274, -0.04853673,
-0.13183856, 0.02047339, -0.04208248, -0.08593107, 0.01927994,
0.02650769, -0.01800761, -0.04549789, -0.07029027, -0.00748984,
-0.00123388, 0.00353033, -0.2068988 , -0.01468842, 0.17282685,
-0.03570998, -0.01473052, -0.02985004, 0.03747841, -0.02289796,
-0.04722409, -0.16702499, -0.12912483, 0.04226191, -0.14368337,
0.01790933, -0.19011118, 0.03639563, -0.02296821, -0.04271722,
-0.04067085, -0.142977 , -0.03574736, -0.00427567])
两个数组的大小相同:
x.shape
Out: (99,)
y.shape
Out: (99,)
然而,当我运行
AxisError: axis 1 is out of bounds for array of dimension 1
我尝试过对两个变量和其中一个变量进行转置,但没有任何方法奏效。
np.concatenate
接受什么输入?基于 the documentation 我希望我的方法能奏效。
正如@hpaulj 所说,它需要一个二维数组 - 可能只是编写库的奇怪方式,在你之前添加以下代码 运行 当我尝试时聚类起作用了:
x = x.reshape(99,1)
y = y.reshape(99,1)
我想使用以下方法连接两个 Numpy 数组:
np.concatenate((x,y.reshape(len(y),1)),axis=1)
x
array([0.02542383, 0.05432444, 0.05592916, 0.0225309 , 0.05751058,
0.05878261, 0.22347298, 0.32191235, 0.02411838, 0.25474137,
0.04921983, 0.05736983, 0.05435839, 0.01524537, 0.05145499,
0.07242904, 0.0506223 , 0.19234735, 0.05399891, 0.0410024 ,
0.03938462, 0.07316477, 0.01000894, 0.01053533, 0.19936873,
0.41291729, 0.04906247, 0.02723546, 0.01838214, 0.06434103,
0.26908878, 0.10925268, 0.20858194, 0.03522793, 0.04499719,
0.03410352, 0.02554791, 0.09302561, 0.03608627, 0.04368193,
0.0271514 , 0.10271527, 0.07826084, 0.0166053 , 0.13437232,
0.10548925, 0.07658451, 0.02076723, 0.03385754, 0.02455683,
0.04214978, 0.1913195 , 0.02690974, 0.00714601, 0.14730562,
0.09305552, 0.06944146, 0.11340955, 0.10525494, 0.04790132,
0.05222447, 0.07743867, 0.04675769, 0.03493571, 0.0444973 ,
0.09345969, 0.04027045, 0.03830293, 0.06390374, 0.06208764,
0.04554125, 0.01742904, 0.03830261, 0.06413129, 0.02297048,
0.03130876, 0.05521549, 0.14778974, 0.02137831, 0.17142863,
0.03001146, 0.0176135 , 0.02883904, 0.03828 , 0.0202778 ,
0.03461585, 0.12083221, 0.09090906, 0.04827766, 0.09999199,
0.04247083, 0.13864809, 0.05922635, 0.0201329 , 0.04460693,
0.04079322, 0.09750553, 0.0329554 , 0.05622296])
y
array([-0.02264446, 0.02542564, 0.04211922, -0.02332023, 0.00414108,
-0.07603503, 0.21184521, 0.25857056, -0.02607102, 0.23368499,
-0.06407522, 0.03897381, 0.03183766, -0.00508868, -0.0685759 ,
0.02609174, -0.05864956, 0.15634075, -0.05422548, -0.03422613,
-0.03380019, 0.04736571, -0.01302442, 0.00907436, -0.27951327,
0.33882699, -0.06054897, -0.0261247 , -0.01752124, -0.08576588,
-0.38324596, 0.08439715, -0.25341709, -0.02779527, 0.03147691,
0.00644152, -0.02657317, -0.13311193, -0.02792882, -0.05643179,
-0.0334482 , -0.09923616, 0.04261594, -0.01999107, 0.06820104,
-0.13978655, 0.01447225, -0.02443087, -0.02772215, -0.01314321,
0.01165549, 0.04264553, -0.02124456, -0.00884472, -0.0297479 ,
-0.1328692 , 0.05718329, 0.08992262, 0.01722447, -0.05886641,
0.00873129, 0.05607011, -0.04796337, -0.01090274, -0.04853673,
-0.13183856, 0.02047339, -0.04208248, -0.08593107, 0.01927994,
0.02650769, -0.01800761, -0.04549789, -0.07029027, -0.00748984,
-0.00123388, 0.00353033, -0.2068988 , -0.01468842, 0.17282685,
-0.03570998, -0.01473052, -0.02985004, 0.03747841, -0.02289796,
-0.04722409, -0.16702499, -0.12912483, 0.04226191, -0.14368337,
0.01790933, -0.19011118, 0.03639563, -0.02296821, -0.04271722,
-0.04067085, -0.142977 , -0.03574736, -0.00427567])
两个数组的大小相同:
x.shape
Out: (99,)
y.shape
Out: (99,)
然而,当我运行
AxisError: axis 1 is out of bounds for array of dimension 1
我尝试过对两个变量和其中一个变量进行转置,但没有任何方法奏效。
np.concatenate
接受什么输入?基于 the documentation 我希望我的方法能奏效。
正如@hpaulj 所说,它需要一个二维数组 - 可能只是编写库的奇怪方式,在你之前添加以下代码 运行 当我尝试时聚类起作用了:
x = x.reshape(99,1)
y = y.reshape(99,1)