国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > Python > 正文

對(duì)numpy.append()里的axis的用法詳解

2020-02-15 22:04:55
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

如下所示:

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):

簡(jiǎn)答來(lái)說(shuō),就是arr和values會(huì)重新組合成一個(gè)新的數(shù)組,做為返回值。而axis是一個(gè)可選的值

當(dāng)axis無(wú)定義時(shí),是橫向加成,返回總是為一維數(shù)組!

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

當(dāng)axis有定義的時(shí)候,分別為0和1的時(shí)候。(注意加載的時(shí)候,數(shù)組要設(shè)置好,行數(shù)或者列數(shù)要相同。不然會(huì)有error:all the input array dimensions except for the concatenation axis must match exactly)

當(dāng)axis為0時(shí),數(shù)組是加在下面(列數(shù)要相同):

import numpy as npaa= 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.]]

當(dāng)axis為1時(shí),數(shù)組是加在右邊(行數(shù)要相同):

import numpy as npaa= 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.]]

以上這篇對(duì)numpy.append()里的axis的用法詳解就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持武林站長(zhǎng)站。

發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 大悟县| 新宾| 绥德县| 绥江县| 新田县| 桦南县| 泽普县| 正安县| 汾西县| 沁阳市| 天祝| 泰来县| 博罗县| 景洪市| 延川县| 错那县| 邮箱| 香港| 龙游县| 禹城市| 抚顺县| 澜沧| 舒兰市| 本溪| 康保县| 荥阳市| 扶沟县| 惠水县| 大港区| 吐鲁番市| 宁远县| 大埔县| 阳城县| 宣武区| 重庆市| 宜城市| 丰台区| 安溪县| 古丈县| 定结县| 贵州省|