numpy 自学(1)基础篇

numpy的官方的开发指南:https://docs.scipy.org/doc/numpy/user/quickstart.html

         NumPy的主要对象是相同元素的多维数组。这是一个所有的元素都是一种类型、通过一个正整数元组索引的元素表格(通常是元素是数字)。在NumPy中维度(dimensions)叫做轴(axes)。
        例如,在3D空间一个点的坐标[1, 2, 3]有一个轴,轴中有3个元素,所以长度为3。在以下例子中,数组有两个轴,第一个维度长度为2,第二个维度长度为3.
[[ 1., 0., 0.],
 [ 0., 1., 2.]]
        NumPy的数组类被称作ndarray。通常被称作数组。注意numpy.array和标准Python库类array.array并不相同,后者只处理一维数组和提供少量功能。更多重要ndarray对象属性有:

  • ndarray.ndim:数组轴的个数 
  • ndarray.shape:数组的维度。这是一个指示数组在每个维度上大小的整数元组。例如一个n行m列的矩阵,它的shape属性将是(n,m),这个元组的长度是轴的个数,即维度或者ndim属性
  • ndarray.size:数组元素的总个数,等于shape属性中元组元素的乘积。
  • ndarray.dtype:用来描述数组中元素类型的对象,可以通过创造或指定dtype使用标准Python类型。另外NumPy提供它自己的数据类型,如own. numpy.int32, numpy.int16, and numpy.float
  • ndarray.itemsize:数组中每个元素的字节大小。例如,一个元素类型为float64的数组itemsiz属性值为8(=64/8),又如,一个元素类型为complex32的数组item属性为4(=32/8).等同于ndarray.dtype.itemsize
  • ndarray.data:包含实际数组元素的缓冲区,通常我们不需要使用这个属性,因为我们总是通过索引来使用数组中的元素。

 
Microsoft Windows [版本 10.0.15063]
(c) 2017 Microsoft Corporation。保留所有权利。

C:\Users\lenovo>python
Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:54:40) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> a=np.arange(15).reshap(3,5)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'numpy.ndarray' object has no attribute 'reshap'
>>> a=np.arange(15).reshape(3,5)
>>> a
array([[ 0,  1,  2,  3,  4],
       [ 5,  6,  7,  8,  9],
       [10, 11, 12, 13, 14]])
>>>
>>> a.ndim
2
>>> a.dtype.name
'int32'
>>>
>>> a.itemsize
4
>>> a.size
15
>>> type(a)
<class 'numpy.ndarray'>
>>> b=array([6,7,8])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'array' is not defined
>>> b = array([6,7,8])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'array' is not defined
>>> from numpy import *
>>>  b = array([6,7,8])
  File "<stdin>", line 1
    b = array([6,7,8])
    ^
IndentationError: unexpected indent
>>> test =array([6,7,8])
>>> test
array([6, 7, 8])
>>>
>>> tybe(test)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'tybe' is not defined
>>>
>>> type(test)
<class 'numpy.ndarray'>
>>>
>>>
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

段智华

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值