日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

numpy(1)-numpy.ndarray

發布時間:2025/3/12 编程问答 56 豆豆
生活随笔 收集整理的這篇文章主要介紹了 numpy(1)-numpy.ndarray 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

lass numpy.ndarray(shape, dtype=float, buffer=None, offset=0, strides=None, order=None)

數組對象表示由固定大小的項目組成的多維同構數組。關聯的數據類型對象描述數組中每個元素的格式(字節順序、占用內存的字節數、它是整數、浮點數還是其他什么,等等)。
數組應該使用數組、零或空來構造(參見下面的部分)。這里給出的參數指的是用于實例化數組的低級方法(ndarray(…))。

Parameters:
(for the new method; see Notes below)
shape : tuple of ints
Shape of created array.

dtype : data-type, optional
Any object that can be interpreted as a numpy data type.

buffer : object exposing buffer interface, optional
Used to fill the array with data.

offset : int, optional
Offset of array data in buffer.

strides : tuple of ints, optional
Strides of data in memory.
內存中的數據步長。

order : {‘C’, ‘F’}, optional
Row-major (C-style) or column-major (Fortran-style) order.

numpy.array
Construct an array.
numpy.zeros
Create an array, each element of which is zero.
numpy.empty
Create an array, but leave its allocated memory unchanged (i.e., it contains “garbage”).
numpy.dtype
Create a data-type.

不指定buffer,將隨機生成

np.ndarray(shape=(2,2), dtype=float, order='F') Out[5]: array([[1.16530247e-311, 9.29359819e-315],[5.03946959e-322, 1.16536144e-311]])

指定buffer,則依據數組生成,offset表示從buffer的什么位置開始生成

import numpy as npa=np.ndarray((2,), buffer=np.array([1,2,3]),offset=np.int_().itemsize,dtype=int) print(a)a=np.ndarray((3,), buffer=np.array([1,2,3,4,5,6]),offset=np.int_().itemsize*2,dtype=int) print(a)

[2 3]
[3 4 5]

[-5,0]之間

5 * np.random.random_sample((3, 2)) - 5 array([[-3.99149989, -0.52338984],[-2.99091858, -0.79479508],[-1.23204345, -1.75224494]])

總結

以上是生活随笔為你收集整理的numpy(1)-numpy.ndarray的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。