雅典娜的疑问 2021-11-17 16:19 采纳率: 100%
浏览 1308
已结题

concatenate()出错:ValueError: all the input arrays must have same number of dimensions


u_c_new = clf1.predict(u_d)  # 这里直接使用有标签数据训练得到的SVM模型对无标签数据进行分类,将其分类结果作为无标签数据的类别
cu, cl = 0.0001, 1           # 初始化有标签数据无标签数据重要程度的折中【参数】
sample_weight = np.ones(n)   # 样本权重, 直接让有标签数据的权重为Cl,无标签数据的权重为Cu
print(u_c_new.shape)
print(type(u_c_new))
print(l_c.shape)
print(type(l_c))
# sample_weight[len(l_c):] = cu
# id_set = np.arange(len(u_d))
lu_c = np.concatenate((l_c, u_c_new))

结果为:

(113, 1)
<class 'numpy.ndarray'>
(60, 1)
<class 'numpy.ndarray'>
Traceback (most recent call last):
  File "E:/PYTHON/PYCHARM/Demo/TSVM2.py", line 48, in <module>
    lu_c = np.concatenate((l_c, u_c_new))
  File "<__array_function__ internals>", line 6, in concatenate
ValueError: all the input arrays must have same number of dimensions, but the array at index 0 has 2 dimension(s) and the array at index 1 has 1 dimension(s)

从Debugger中看到u_c_new:{ndarray:(113,)} ; 而l_c:{ndarray:(60,1)} ,这是为什么呀?怎么解决呀?

  • 写回答

2条回答 默认 最新

  • CSDN专家-HGJ 2021-11-17 17:06
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
  • 雅典娜的疑问 2021-11-18 11:22
    关注

    解决上述问题有两种方法:

    u_c_new = pd.DataFrame(u_c_new)
    lu_c = np.concatenate((l_c, u_c_new))
    

    或者

    u_c_new = u_c_new.reshape((n,m))     # n,m根据自身数据决定
    lu_c = np.concatenate((l_c, u_c_new))
    

    当拼接在循环中,每一次拼接之前都需要进行reshape或者dataframe转换

    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 11月27日
  • 已采纳回答 11月19日
  • 创建了问题 11月17日

悬赏问题

  • ¥15 Java环境配了,但启用不成功。
  • ¥15 求一个智能家居控制的代码
  • ¥15 ad软件 pcb布线pcb规则约束编辑器where the object matpcb布线pcb规则约束编辑器where the object matchs怎么没有+15v只有no net
  • ¥15 虚拟机vmnet8 nat模式可以ping通主机,主机也能ping通虚拟机,但是vmnet8一直未识别怎么解决,其次诊断结果就是默认网关不可用
  • ¥20 求各位能用我能理解的话回答超级简单的一些问题
  • ¥15 yolov5双目识别输出坐标代码报错
  • ¥15 这个代码有什么语法错误
  • ¥15 给予STM32按键中断与串口通信
  • ¥15 使用QT实现can通信
  • ¥15 关于sp验证的一些东西,求告知如何解决,