python与数据处理:Numpy中的数组(一、简介)

本文介绍了Numpy库中的核心数据结构——ndarray,它是一个用于存储同种类型数据的多维容器。数组的形状定义了其维度大小,而数据类型由dtype对象指定。通过索引和切片,可以访问和修改数组内容。此外,多个ndarray可能共享数据,形成视图和基的概念。了解这些基础知识对于高效地进行数据处理至关重要。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

python与数据处理:Numpy中的数组(一、简介)

文本译自Numpy官方API文档,原文附在文末。

Numpy中的数组由ndarray类实现。ndarray是一个能够储存同一类型和位数(译者注:一般是32位或64位)数据的多维数据容器。数组的容量和维数由其本身的形状决定;而对于一个n维数组,其形状又可以由一个元组表示,这个元组拥有n个非负整数,从而能够定义每个维度上的大小。数组内元素的类型由另外一个专门用来定义数据类型的类(dtype)确定。对于每一个数组,dtype是唯一确定的。
如同python中其他的数据容器,我们可以通过索引或切割来获取或修改原数组储存的数据;也可以调用adarray自带的方法和属性(译者注:这里的“属性”指“成员变量”或“域”)对其进行操作。
不同的ndarray可能共享相同的数据,所以对其中一个ndarray的操作可能会对另一个产生影响。在这种情况下,我们称其中一个是另一个的“视图”;相应地,另一个就是这一个的“基”。如果python中的类(如字符串)实现了buffer或array接口,那么这些类也能成为ndarray的“视图”

An ndarray is a (usually fixed-size) multidimensional container of items of the same type and size. The number of dimensions and items in an array is defined by its shape, which is a tuple of N non-negative integers that specify the sizes of each dimension. The type of items in the array is specified by a separate data-type object (dtype), one of which is associated with each ndarray.
As with other container objects in Python, the contents of an ndarray can be accessed and modified by indexing or slicing the array (using, for example, N integers), and via the methods and attributes of the ndarray.
Different ndarrays can share the same data, so that changes made in one ndarray may be visible in another. That is, an ndarray can be a “view” to another ndarray, and the data it is referring to is taken care of by the “base” ndarray. ndarrays can also be views to memory owned by Python strings or objects implementing the buffer or array interfaces.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值