对python numpy.array插入一行或一列的方法详解

作者:易_ 时间:2022-12-08 15:44:07 

如下所示:


import numpy as np
a = np.array([[1,2,3],[4,5,6],[7,8,9]])
b = np.array([[0,0,0]])
c = np.insert(a, 0, values=b, axis=0)
d = np.insert(a, 0, values=b, axis=1)
print(c)
print(d)

>>c
[[0 0 0]
[1 2 3]
[4 5 6]
[7 8 9]]

>>d
[[0 1 2 3]
[0 4 5 6]
[0 7 8 9]]

来源:https://blog.csdn.net/hang916/article/details/82828234

标签:python,numpy,array
0
投稿

猜你喜欢

  • Python with关键字,上下文管理器,@contextmanager文件操作示例

    2022-06-22 05:33:12
  • 详解JS中的compose函数和pipe函数用法

    2024-04-18 10:59:25
  • mysql启用skip-name-resolve模式时出现Warning的处理办法

    2024-01-25 09:38:44
  • 解决python中画图时x,y轴名称出现中文乱码的问题

    2023-08-04 09:00:23
  • python geopandas读取、创建shapefile文件的方法

    2022-09-23 16:57:19
  • SQL server中字符串逗号分隔函数分享

    2024-01-12 17:20:22
  • PDO取Oracle lob大字段,当数据量太大无法取出的问题的解决办法

    2009-04-30 18:41:00
  • Python全面解析json数据并保存为csv文件

    2021-02-14 03:26:26
  • Python常见错误:IndexError: list index out of range解决

    2021-02-17 21:53:10
  • Cython处理C字符串的示例详解

    2021-12-03 01:17:27
  • Mysql入门系列:MYSQL日志文件维护

    2008-11-24 13:10:00
  • python多线程爬取西刺代理的示例代码

    2021-05-27 04:32:57
  • python基于pyppeteer制作PDF文件

    2021-09-28 20:56:24
  • golang协程设计及调度原理

    2024-02-21 21:16:51
  • 使用 Python 实现简单的 switch/case 语句的方法

    2021-02-02 09:10:16
  • ASP判断E-Mail的合法性,以及过滤邮箱字符

    2010-05-27 12:23:00
  • 详解MySQL数据库--多表查询--内连接,外连接,子查询,相关子查询

    2024-01-24 05:20:34
  • pandas分批读取大数据集教程

    2023-01-13 16:45:32
  • 如何判断电子邮件的地址格式是否正确?

    2010-01-12 20:12:00
  • 解读MySQL的InnoDB引擎日志工作原理

    2011-01-04 19:59:00
  • asp之家 网络编程 m.aspxhome.com