亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁技術(shù)文章
文章詳情頁

python如何建立全零數(shù)組

瀏覽:31日期:2022-07-17 08:29:53

語句格式:

numpy.zeros(shape, dtype=float, order=’C’)

參數(shù)說明:

shape:整型或元素為整型的序列,表示生成的新數(shù)組的shape,如(2,3)或 2。

dtype:生成數(shù)組的數(shù)據(jù)格式,如numpy.int8。默認為numpy.float64。

order:{’C’, ’F’}可選,是否將多維數(shù)據(jù)存儲為C-或Fortran-contiguous(按行或按列)順序。

返回值:ndarray,一個指定了shape, dtype, order的零數(shù)組。

示例見下:

第四個例子看起來很方便。

Numpy文檔原文:

numpy.zerosnumpy.zeros(shape, dtype=float, order=’C’)Return a new array of given shape and type, filled with zeros.Parameters:shape : int or sequence of intsShape of the new array, e.g., (2, 3) or 2.dtype : data-type, optionalThe desired data-type for the array, e.g., numpy.int8. Default is numpy.float64.order : {‘C’, ‘F’}, optionalWhether to store multidimensional data in C- or Fortran-contiguous (row- or column-wise) order in memory.Returns:out : ndarray

Array of zeros with the given shape, dtype, and order.

#指定長度的一維數(shù)組>>> np.zeros(5)array([ 0., 0., 0., 0., 0.]) #指定數(shù)據(jù)類型,指定長度的一維數(shù)組>>> np.zeros((5,), dtype=int)array([0, 0, 0, 0, 0]) #二維數(shù)組>>> np.zeros((2, 1))array([[ 0.], [ 0.]]) >>> s = (2,2)>>> np.zeros(s)array([[ 0., 0.], [ 0., 0.]]) #指定dtype>>> np.zeros((2,), dtype=[(’x’, ’i4’), (’y’, ’i4’)]) # custom dtypearray([(0, 0), (0, 0)], dtype=[(’x’, ’<i4’), (’y’, ’<i4’)])

內(nèi)容擴展:

python創(chuàng)建數(shù)組的方法

直接定義法:

1.直接定義

matrix=[0,1,2,3]

2.間接定義

matrix=[0 for i in range(4)]print(matrix)

Numpy方法:

Numpy內(nèi)置了從頭開始創(chuàng)建數(shù)組的函數(shù):

zeros(shape)將創(chuàng)建一個用指定形狀用0填充的數(shù)組。默認的dtype是float64。

下面是幾種常用的創(chuàng)建方法:

#coding=utf-8import numpy as npa = np.array([1,2,3,4,5])print ab = np.zeros((2,3))print bc = np.arange(10)print cd = np.arange(2,10,dtype=np.float)print de = np.linspace(1.0,4.0,6)print ef = np.indices((3,3))print f

到此這篇關(guān)于python如何建立全零數(shù)組的文章就介紹到這了,更多相關(guān)python建立全零數(shù)組的方法內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 91在线精品中文字幕 | 色综合图片二区150p | 亚洲综合网站 | 国产精品对白刺激久久久 | 高h喷水荡肉爽文np肉色文 | 免费国产成人高清在线观看不卡 | 嗯 用劲 好爽 好深 免费视频 | 亚洲欧美日韩中文v在线 | 黄色成人影院 | 久久福利一区二区三区 | 欧美成人亚洲 | 美国黄色一级大片 | 久久久久欧美精品观看 | 国产激情一区二区三区在线观看 | 国产丰满主播丝袜勾搭秀 | 成人爽a毛片在线视频 | 欧美金妇欧美乱妇视频 | 国产精品福利视频主播真会玩 | 中文字幕亚洲另类天堂 | 日本丝袜一区 | a级一级片 | 欧美一级欧美三级在线观看 | 日产一区二区三区精品视频 | 国内外成人在线视频 | 久久99青青久久99久久 | 男女全黄做爰视频免费看 | 久久精品成人国产午夜 | 97久视频精品视频在线老司机 | 国产我不卡 | 黄色网页免费大全 | 丝袜 亚洲 另类 欧美 变态 | 亚洲乱码中文字幕综合 | 看美国毛片 | 在线日本妇人成熟免费观看 | 久久免费99精品久久久久久 | 成人网视频在线观看免费 | 久久精品中文字幕极品 | 精品国产综合区久久久久99 | 亚洲综合一区二区不卡 | 国产不卡视频在线 | 国产情趣酒店鸳鸯浴在线观看 |