av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁技術文章
文章詳情頁

python如何建立全零數組

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

語句格式:

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

參數說明:

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

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

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

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

示例見下:

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

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.

#指定長度的一維數組>>> np.zeros(5)array([ 0., 0., 0., 0., 0.]) #指定數據類型,指定長度的一維數組>>> np.zeros((5,), dtype=int)array([0, 0, 0, 0, 0]) #二維數組>>> 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’)])

內容擴展:

python創建數組的方法

直接定義法:

1.直接定義

matrix=[0,1,2,3]

2.間接定義

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

Numpy方法:

Numpy內置了從頭開始創建數組的函數:

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

下面是幾種常用的創建方法:

#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

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

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 91免费观看视频 | 久久久久亚洲国产| 在线观看国产视频 | 81精品国产乱码久久久久久 | 亚洲高清视频一区二区 | 欧美精品一区二区蜜桃 | 亚洲精品一区二区在线观看 | 福利在线观看 | 激情欧美一区二区三区中文字幕 | 成人免费在线播放 | 欧美区在线 | 国产区精品 | 久久精品99 | 一区中文字幕 | 国产综合视频 | 高清视频一区二区三区 | 日韩av网址在线观看 | 一区二区三区久久久 | a级片在线观看 | 欧洲一级毛片 | 亚洲成人精品影院 | 成人午夜激情 | 精品国产乱码久久久久久丨区2区 | 作爱视频免费观看 | 日韩一区二区在线视频 | 日韩免费中文字幕 | 成人国产午夜在线观看 | 欧美精品一二三 | 免费看国产一级特黄aaaa大片 | 91一区二区三区 | 成在线人视频免费视频 | 视频一二三区 | 午夜精品久久久久久久99黑人 | 在线播放中文字幕 | 狠狠爱视频 | 中文一级片| 亚洲精品久久久久久下一站 | 成人免费一区二区三区视频网站 | 日日爽 | 日韩一区二区三区精品 | 国产99免费视频 |