在 NumPy 中返回一个新的三维数组,不初始化条目,并将数据以列主序存储
要返回一个新的三维数组,而不初始化条目,请在 Python NumPy 中使用 **numpy.empty()** 方法。第一个参数是空数组的形状。使用“order”参数更改顺序。我们将 order 设置为“F”,即 Fortran 样式,这意味着将数据以列主序存储在内存中。
dtype 是数组所需的输出数据类型,例如 numpy.int8。默认值为 numpy.float64。order 表示是否以行主序(C 样式)或列主序(Fortran 样式)顺序将多维数据存储在内存中。
函数 empty() 返回一个具有给定形状、dtype 和顺序的未初始化(任意)数据的数组。对象数组将初始化为 None。
步骤
首先,导入所需的库 -
import numpy as np
使用 Python NumPy 中的 numpy.empty() 方法返回一个新的三维数组,而不初始化条目。使用“order”参数更改顺序 -
arr = np.empty([3, 3, 3], order = 'F')
显示数组 -
print("Array...
",arr)获取数组的类型 -
print("
Array type...
", arr.dtype)
获取数组的维度 -
print("
Our Array Dimensions...
", arr.ndim)获取数组中的元素数量 -
print("
Number of elements...
", arr.size)
示例
import numpy as np
# To return a new Three-Dimensional array, without initializing entries, use the numpy.empty() method in Python Numpy
# The 1st parameter is the Shape of the empty array
# The order is changed using the "order" parameter
# We have set the order to "F" i.e. Fortran-style, that means to store the data in column-major order in memory
arr = np.empty([3, 3, 3], order = 'F')
# Display the array
print("Array...
",arr)
# Get the type of the array
print("
Array type...
", arr.dtype)
# Get the dimensions of the Array
print("
Our Array Dimensions...
", arr.ndim)
# Get the number of elements in the Array
print("
Number of elements...
", arr.size)输出
Array... [[[4.64748890e-310 6.91009533e-310 6.90996148e-310] [6.91009686e-310 6.91009685e-310 6.91009688e-310] [6.91009520e-310 6.91009686e-310 6.91009688e-310]] [[0.00000000e+000 6.90996148e-310 6.91009686e-310] [6.91009687e-310 6.91009685e-310 6.91009685e-310] [6.90996151e-310 6.91009682e-310 6.91009686e-310]] [[6.91009686e-310 6.90996148e-310 6.90996148e-310] [6.91009687e-310 6.90996148e-310 6.90996148e-310] [6.91009686e-310 6.91009688e-310 1.10670705e-321]]] Array type... float64 Our Array Dimensions... 3 Number of elements... 27
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP