numpy 数组元素的拼接(append)

接上一期博客

numpy 数组元素的拼接 (concatenate)

numpy.append(arr, values, axis=None)

官方文档

功能:

如果指定了axis,则把arraxis指定的维度进行切片,并把values拼接在最后.
如果没有指定axis,则把arrvalues都做扁平化处理.
(要求valuesaxis指定的维度之外的其他维度和arr有相同的形状)

参数

These values are appended to a copy of . It must be of the correct shape (**the same shape as** , **excluding axis**注意,要求values在axis指定的维度之外的其他维度和arr有相同的形状)). If axis is not specified, values can be any shape and will be flattened before use.

示例

>>>np.append([1, 2, 3], [[4, 5, 6], [7, 8, 9]])
array([1, 2, 3, ..., 7, 8, 9])

When axis is specified, values must have the correct shape.

>>>np.append([[1, 2, 3], [4, 5, 6]], [[7, 8, 9]], axis=0)
array([[1, 2, 3],
       [4, 5, 6],
       [7, 8, 9]])
>>>np.append([[1, 2, 3], [4, 5, 6]], [7, 8, 9], axis=0)
Traceback (most recent call last):
    ...
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)

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值