- 教程
- 介绍
- 环境
- Ndarray 对象(Ndarray Object)
- 数据类型
- 数组属性(Array Attributes)
- 阵列创建例程(Array Creation Routines)
- 来自现有数据的数组(Array from Existing Data)
- 数值范围中的数组(Array From Numerical Ranges)
- 数值范围中的数组(Array From Numerical Ranges)
- 数值范围中的数组(Array From Numerical Ranges)
- 广播(Broadcasting)
- 迭代数组(Iterating Over Array)
- 数组操作(Array Manipulation)
- Binary 运算符
- 字符串函数(String Functions)
- 数学函数(Mathematical Functions)
- 算术运算(Arithmetic Operations)
- 统计函数(Statistical Functions)
- 统计函数(Statistical Functions)
- 字节交换(Byte Swapping)
- 副本和视图(Copies & Views)
- 矩阵库(Matrix Library)
- 线性代数(Linear Algebra)
- Matplotlib(Matplotlib)
- 使用Matplotlib的直方图(Histogram Using Matplotlib)
- I/O with NumPy
- 有用的资源
- reshape
- flat
- flatten
- ravel
- transpose
- ndarray.T
- rollaxis
- swapaxes
- broadcast
- broadcast_to
- expand_dims
- squeeze
- concatenate
- stack
- hstack
- vstack
- split
- hsplit
- vsplit
- resize
- append
- insert
- delete
- unique
- bitwise_and
- bitwise_or
- invert
- left_shift
- right_shift
- add()
- multiply()
- center()
- capitalize()
- title()
- lower()
- upper()
- split()
- splitlines()
- strip()
- join()
- replace()
- decode()
- encode()
- dot
- vdot
- inner
- matmul
- determinant
- solve
- inv
文章来源于网络收集而来,版权归原创者所有,如有侵权请及时联系!
insert
此函数沿给定轴和给定索引之前在输入数组中插入值。 如果将值的类型转换为插入,则它与输入数组不同。 插入没有到位,函数返回一个新数组。 此外,如果未提及轴,则输入数组变平。
insert()函数采用以下参数 -
numpy.insert(arr, obj, values, axis)
Where,
Sr.No. | 参数和描述 |
---|---|
1 | arr 输入数组 |
2 | obj 要进行插入的索引 |
3 | values 要插入的值数组 |
4 | axis 要插入的轴。 如果没有给出,则输入数组被展平 |
例子 (Example)
import numpy as np
a = np.array([[1,2],[3,4],[5,6]])
print 'First array:'
print a
print '\n'
print 'Axis parameter not passed. The input array is flattened before insertion.'
print np.insert(a,3,[11,12])
print '\n'
print 'Axis parameter passed. The values array is broadcast to match input array.'
print 'Broadcast along axis 0:'
print np.insert(a,1,[11],axis = 0)
print '\n'
print 'Broadcast along axis 1:'
print np.insert(a,1,11,axis = 1)
其产出如下 -
First array:
[[1 2]
[3 4]
[5 6]]
Axis parameter not passed. The input array is flattened before insertion.
[ 1 2 3 11 12 4 5 6]
Axis parameter passed. The values array is broadcast to match input array.
Broadcast along axis 0:
[[ 1 2]
[11 11]
[ 3 4]
[ 5 6]]
Broadcast along axis 1:
[[ 1 11 2]
[ 3 11 4]
[ 5 11 6]]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论