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

首頁 > 編程 > Python > 正文

Python numpy生成矩陣、串聯(lián)矩陣代碼分享

2020-02-16 10:55:33
字體:
供稿:網(wǎng)友

import numpy

生成numpy矩陣的幾個(gè)相關(guān)函數(shù):

numpy.array()
numpy.zeros()
numpy.ones()
numpy.eye()

串聯(lián)生成numpy矩陣的幾個(gè)相關(guān)函數(shù):

numpy.array()
numpy.row_stack()
numpy.column_stack()
numpy.reshape()

>>> import numpy >>> numpy.eye(3) array([[ 1., 0., 0.],     [ 0., 1., 0.],     [ 0., 0., 1.]]) >>> numpy.zeros(3) array([ 0., 0., 0.]) >>> numpy.ones(3) array([ 1., 1., 1.]) >>> x1 = numpy.array((1, 2, 3)) >>> x1 array([1, 2, 3]) >>> x2 = numpy.array([4, 5, 6]) >>> x2 array([4, 5, 6]) >>> x3 = numpy.array((x1, x2)) >>> x3 array([[1, 2, 3],     [4, 5, 6]]) >>> x4 = x3.reshape(2, 3) >>> x4 array([[1, 2, 3],     [4, 5, 6]]) >>> x4 = x3.reshape(3, 2) >>> x4 array([[1, 2],     [3, 4],     [5, 6]]) >>> x5 = numpy.row_stack(x1, x2) Traceback (most recent call last):  File "<stdin>", line 1, in <module> TypeError: vstack() takes exactly 1 argument (2 given) >>> x5 = numpy.row_stack((x1, x2)) >>> x5 array([[1, 2, 3],     [4, 5, 6]]) >>> x6 = numpy.row_stack([x1, x2]) >>> x6 array([[1, 2, 3],     [4, 5, 6]]) >>> x7 = numpy.row_stack((x6, x2)) >>> x7 array([[1, 2, 3],     [4, 5, 6],     [4, 5, 6]]) >>> x7[0] array([1, 2, 3]) >>> x7[1] array([4, 5, 6]) >>> x7[2] array([4, 5, 6]) >>> x8 = numpy.column_stack([x1, x2, x1, x2]) >>> x8 array([[1, 4, 1, 4],     [2, 5, 2, 5],     [3, 6, 3, 6]]) >>> x8[0] array([1, 4, 1, 4]) >>> x8[1] array([2, 5, 2, 5]) >>> x8[2] array([3, 6, 3, 6]) >>> x8[3] Traceback (most recent call last):  File "<stdin>", line 1, in <module> IndexError: index 3 is out of bounds for axis 0 with size 3 >>> x8[0][3] 4 >>> 

python生成1行四列全2矩陣

print np.ones((1,4))*2

總結(jié)

以上就是本文關(guān)于Python numpy生成矩陣、串聯(lián)矩陣代碼分享的全部?jī)?nèi)容,希望對(duì)大家有所幫助。感興趣的朋友可以繼續(xù)參閱本站其他相關(guān)專題,如有不足之處,歡迎留言指出。感謝朋友們對(duì)本站的支持!

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 肥乡县| 南木林县| 济宁市| 海原县| 黄石市| 靖州| 阿拉善左旗| 攀枝花市| 永寿县| 西畴县| 乌兰察布市| 灌云县| 伊吾县| 五华县| 武山县| 襄樊市| 鹤庆县| 康保县| 会理县| 页游| 富蕴县| 满洲里市| 保靖县| 宁化县| 义乌市| 嘉禾县| 郴州市| 江安县| 西林县| 辽阳市| 绥棱县| 伊吾县| 四子王旗| 昌图县| 余庆县| 班戈县| 宁明县| 桃江县| 炎陵县| 婺源县| 永年县|