热线电话:13121318867

登录
2019-01-10 阅读量: 672
Numpy中的N维数组

Numpy中的数组是一个元素表(通常是数字),它们都是相同的类型,由正整数元组索引。在Numpy中,数组的维数被称为数组的等级。沿每个维度给出数组大小的整数元组称为数组的形状。Numpy中的数组类称为ndarray。Numpy数组中的元素可以使用方括号访问,并且可以使用嵌套的Python列表进行初始化。

示例:

[[1,2,3],
[4,2,5]]

这里,rank = 2(因为它是2维或有2个轴)
第一维(轴)长度= 2,第二维度长度= 3
整体形状可表示为:(2,3)

# Python program to demonstrate

# basic array characteristics

import numpy as np

# Creating array object

arr = np.array( [[ 1, 2, 3],

[ 4, 2, 5]] )

# Printing type of arr object

print("Array is of type: ", type(arr))

# Printing array dimensions (axes)

print("No. of dimensions: ", arr.ndim)

# Printing shape of array

print("Shape of array: ", arr.shape)

# Printing size (total number of elements) of array

print("Size of array: ", arr.size)

# Printing type of elements in array

print("Array stores elements of type: ", arr.dtype)

0.0000
4
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子