使用numpy.concatenate()时报错:TypeError: only integer scalar arrays can be converted to a scalar index

想要实现numpy数组按列拼接(合并),使用numpy.concatenate函数
函数说明
我写成了:

x=np.linspace(1,100,10)
ones=np.ones(len(x))
X=np.concatenate(x,ones,axis=0)
报错:TypeError: only integer scalar arrays can be converted to a scalar index

应该写成:

X=np.concatenate((x,ones),axis=0)

输出:

[  1.  12.  23.  34.  45.  56.  67.  78.  89. 100.   1.   1.   1.   1.
1.   1.   1.   1.   1.   1.]

补充:要实现增加一列数字,使用numpy.c_[]或者numpy.r_[]
其中numpy.c_[]实现按列添加,numpy.r_[]实现按行添加

np.c_[]

x=np.linspace(1,100,10)
ones=np.ones(len(x))
z=np.c_[ones,x]
[[  1.   1.][  1.  12.][  1.  23.][  1.  34.][  1.  45.][  1.  56.][  1.  67.][  1.  78.][  1.  89.][  1. 100.]]

np.r_[]

x=np.linspace(1,100,10)
ones=np.ones(len(x))
z=np.r_[ones,x]
[  1.   1.   1.   1.   1.   1.   1.   1.   1.   1.   1.  12.  23.  34.45.  56.  67.  78.  89. 100.]

报错’TypeError: only integer scalar arrays can be converted to a scalar index‘相关推荐

  1. TypeError: only integer scalar arrays can be converted to a scalar index

    在取某些索引下的值时,报错TypeError: only integer scalar arrays can be converted to a scalar index data = data[in ...

  2. 成功解决TypeError: only integer scalar arrays can be converted to a scalar index

    成功解决TypeError: only integer scalar arrays can be converted to a scalar index 目录 解决问题 解决思路 解决方法 解决问题 ...

  3. python报错 TypeError: an integer is required

    问题描述: 在本地使用socket向NetAssist传送数据的时候,执行python文件后发现报出python 报错TypeError: an integer is required错误 代码: 1 ...

  4. TypeError: only integer scalar arrays can be converted to a scalar index一例

    问题重现: # -*- coding: utf-8 -*- import sys reload(sys) sys.setdefaultencoding('utf-8') # @Author: appl ...

  5. python创建对象后调用对象的方法,报错TypeError: getName() takes 0 positional arguments but 1 was given

    源码 ## TODO: Create multiple cars and visualize them height = 4 width = 6 world = np.zeros((height, w ...

  6. VUE.JS 使用axios数据请求时数据绑定时 报错 TypeError: Cannot set property 'xxxx' of undefined 的解决办法...

    data里面做了定义 在方法里面进行赋值 用 this.info = repos.data 数据可以请求到,但是会报错 TypeError: Cannot set property 'listgrou ...

  7. Python报错TypeError: 'str' object is not callable

    原文:http://blog.sina.com.cn/s/blog_71f3890901017rsh.html Python报错TypeError: 'str' object is not calla ...

  8. 记录webpack使用问题,使用报错“UnhandledPromiseRejectionWarning,file-loader图片过大,无法加载图片,打包html文件报错TypeError

    记录webpack使用报错 版本号问题 运行npm run build,报错 "UnhandledPromiseRejectionWarning: TypeError: this.getRe ...

  9. Python报错TypeError: ‘User‘ object is not iterable

    Python报错TypeError: 'User' object is not iterable 原因 User对象是不可迭代的,我这里是因为User并不是list,所以是不可迭代的,所以不使用迭代即 ...

  10. [转载]UEditor报错TypeError: me.body is undefined

    本文转载来自: UEditor报错TypeError: me.body is undefined 今天在使用UEditor的setContent的时候报错,报错代码如下 TypeError: me.b ...

最新文章

  1. Linux多任务编程——进程
  2. ubuntu 将某个目录下的文件复制到_命令行 将多个特定文件从一个文件夹复制到另一个文件夹...
  3. 【音频处理】离散傅里叶变换
  4. Object-C,NSArraySortTest,数组排序3种方式
  5. android复位机器人图片_Universal-Image-Loader 图片异步加载类库还不熟?
  6. js添加广告模块,随页面移动而移动
  7. android listpreference 自定义,Android中Fragmen首选项使用自定义的ListPreference的方法
  8. java一维打地鼠_Java编程实现打地鼠文字游戏实例代码
  9. Java语言基础(2)
  10. Educational Codeforces Round 12 B. Shopping 暴力
  11. camerax_Android CameraX概述
  12. oracle startup open ora 03113,Oracle 11g startup时报ORA-03113通信通道的文件结尾
  13. 苹果拼图软件测试,装机必备软件评测:DSM记事本iPhone版
  14. 吃透MIPI接口,你必须了解它这三种PHY规范的区别
  15. python进阶高级技能:Python退火算法在高次方程的应用
  16. 最近很火的程序员成语,你知道几个?
  17. Excel库存表通过吉度PDA盘点机形成盘点差异表
  18. socket error 10053,10054究竟是怎么引起的
  19. java 解密pdf_java – pdfbox:试图解密PDF
  20. 西安财经大学计算机科学学院,西安财经学院

热门文章

  1. 初始化栈的代码_限定性数据结构-栈
  2. python中的common_common:个人基础函数库
  3. 四因素三水平正交试验表_正交实验设计过程
  4. HighCharts:设置饼图不可点击选择
  5. SQL:pgsql查询geom参考系以及更改geom参考系
  6. Node:连接MySQL报错\lib\protocol\Parser.js:43 Cannot read property ‘query‘ of undefined
  7. Vue:embed结合ElementUI中dialog实现PDF文件预览
  8. php7视频处理扩展_PHP7扩展开发之类型处理
  9. Java一键多值Map 之Guava Multimap 用法简介
  10. 为了躲开违规电动车,我一下子撞电线杆上了