博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[已解决]报错:ValueError: Expected 2D array, got scalar array instead
阅读量:4359 次
发布时间:2019-06-07

本文共 573 字,大约阅读时间需要 1 分钟。

报错代码:

new_x = 84610pre_y = model.predict(new_x)print(pre_y)

报错结果:

ValueError: Expected 2D array, got scalar array instead:array=84610.Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.

解决思路:

值错误:应为二维数组,而得到的是一维数组:

使用array重新调整数据的形状。如果数据有单个功能或数组,则重新调整形状(-1,1)。如果数据包含单个示例,则重新调整形状(1,-1)。

解决方案:

加上

new_x = np.array(new_x).reshape(1, -1)

修改后的代码:

new_x = 84610new_x = np.array(new_x).reshape(1, -1)pre_y = model.predict(new_x)print(pre_y)

转载于:https://www.cnblogs.com/hankleo/p/11310272.html

你可能感兴趣的文章
代码回顾
查看>>
对一次系统上线的思考-走出“舒适区”
查看>>
【06】Cent OS 7 中部署 zabbix_server 环境
查看>>
vue 中 vue-router、transition、keep-alive 怎么结合使用?
查看>>
小常识
查看>>
TungstenSecret
查看>>
LR遇到的问题
查看>>
mssql格式化工具——SQL PRETTY PRINTER
查看>>
datagrid删除按钮
查看>>
Redis高级进阶(一)
查看>>
PhysX入门教程(全)
查看>>
Codeforces 948D Perfect Security 【01字典树】
查看>>
android中通过ServerSocket创建端口问题
查看>>
fieldset、legend、display html元素
查看>>
IntelliJ IDEA 14.x 与 Tomcat 集成,创建并运行Java Web项目
查看>>
JavaWeb学习-Tomcat
查看>>
优秀程序员==工作时间长的程序员么?
查看>>
docker学习笔记2:容器操作
查看>>
深入浅出设计模式——访问者模式(Visitor Pattern)
查看>>
【转载】zookeeper 分布式锁 实现
查看>>