黑松山资源网 Design By www.paidiu.com

如下所示:

def append(arr, values, axis=None):
 """
 Append values to the end of an array.
 Parameters
 ----------
 arr : array_like
  Values are appended to a copy of this array.
 values : array_like
  These values are appended to a copy of `arr`. It must be of the
  correct shape (the same shape as `arr`, excluding `axis`). If
  `axis` is not specified, `values` can be any shape and will be
  flattened before use.
 axis : int, optional
  The axis along which `values` are appended. If `axis` is not
  given, both `arr` and `values` are flattened before use.
 Returns
 -------
 append : ndarray
  A copy of `arr` with `values` appended to `axis`. Note that
  `append` does not occur in-place: a new array is allocated and
  filled. If `axis` is None, `out` is a flattened array.

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

简答来说,就是arr和values会重新组合成一个新的数组,做为返回值。而axis是一个可选的值

当axis无定义时,是横向加成,返回总是为一维数组!

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

当axis有定义的时候,分别为0和1的时候。(注意加载的时候,数组要设置好,行数或者列数要相同。不然会有error:all the input array dimensions except for the concatenation axis must match exactly)

当axis为0时,数组是加在下面(列数要相同):

import numpy as np
aa= np.zeros((1,8))
bb=np.ones((3,8))
c = np.append(aa,bb,axis = 0)
print(c)
[[ 0. 0. 0. 0. 0. 0. 0. 0.]
 [ 1. 1. 1. 1. 1. 1. 1. 1.]
 [ 1. 1. 1. 1. 1. 1. 1. 1.]
 [ 1. 1. 1. 1. 1. 1. 1. 1.]]

当axis为1时,数组是加在右边(行数要相同):

import numpy as np
aa= np.zeros((3,8))
bb=np.ones((3,1))
c = np.append(aa,bb,axis = 1)
print(c)
[[ 0. 0. 0. 0. 0. 0. 0. 0. 1.]
 [ 0. 0. 0. 0. 0. 0. 0. 0. 1.]
 [ 0. 0. 0. 0. 0. 0. 0. 0. 1.]]

以上这篇对numpy.append()里的axis的用法详解就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。

黑松山资源网 Design By www.paidiu.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
黑松山资源网 Design By www.paidiu.com

稳了!魔兽国服回归的3条重磅消息!官宣时间再确认!

昨天有一位朋友在大神群里分享,自己亚服账号被封号之后居然弹出了国服的封号信息对话框。

这里面让他访问的是一个国服的战网网址,com.cn和后面的zh都非常明白地表明这就是国服战网。

而他在复制这个网址并且进行登录之后,确实是网易的网址,也就是我们熟悉的停服之后国服发布的暴雪游戏产品运营到期开放退款的说明。这是一件比较奇怪的事情,因为以前都没有出现这样的情况,现在突然提示跳转到国服战网的网址,是不是说明了简体中文客户端已经开始进行更新了呢?