ml-day03

来源:互联网 发布:万能遥控器软件大全 编辑:程序博客网 时间:2024/04/28 18:05
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 positive 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.

ndarray包含的每一个元素的大小和类型都相同的多维数组。

每一个维度的数据类型是dtype

NumPy的主要对象是同种元素的多维数组。这是一个所有的元素都是一种类型、通过一个正整数元组索引的元素表格(通常是元素是数字)。在NumPy中维度(dimensions)叫做轴(axes),轴的个数叫做秩(rank)。

a = [[1,2,3],[1,2,3]]

a是一个二维的数组

item:[1,2,3]

维度:我把多维数组中的一个item叫做维度

size:len(item),每一个维度的len

>>> import numpy as np
>>> np.zeros((3,4,5))
array([[[ 0.,  0.,  0.,  0.,  0.],
        [ 0.,  0.,  0.,  0.,  0.],
        [ 0.,  0.,  0.,  0.,  0.],
        [ 0.,  0.,  0.,  0.,  0.]],

       [[ 0.,  0.,  0.,  0.,  0.],
        [ 0.,  0.,  0.,  0.,  0.],
        [ 0.,  0.,  0.,  0.,  0.],
        [ 0.,  0.,  0.,  0.,  0.]],

       [[ 0.,  0.,  0.,  0.,  0.],
        [ 0.,  0.,  0.,  0.,  0.],
        [ 0.,  0.,  0.,  0.,  0.],
        [ 0.,  0.,  0.,  0.,  0.]]])
>>>

>>> np.shape(n)
(3L, 4L, 5L)

有1个3维数组,包含三个2维数组,每一2个维数组包含4个一维数组,每一个一维数组包含5个元素。

>>> np.zeros((4,4,5))
array([[[ 0.,  0.,  0.,  0.,  0.],
        [ 0.,  0.,  0.,  0.,  0.],
        [ 0.,  0.,  0.,  0.,  0.],
        [ 0.,  0.,  0.,  0.,  0.]],

       [[ 0.,  0.,  0.,  0.,  0.],
        [ 0.,  0.,  0.,  0.,  0.],
        [ 0.,  0.,  0.,  0.,  0.],
        [ 0.,  0.,  0.,  0.,  0.]],

       [[ 0.,  0.,  0.,  0.,  0.],
        [ 0.,  0.,  0.,  0.,  0.],
        [ 0.,  0.,  0.,  0.,  0.],
        [ 0.,  0.,  0.,  0.,  0.]],

       [[ 0.,  0.,  0.,  0.,  0.],
        [ 0.,  0.,  0.,  0.,  0.],
        [ 0.,  0.,  0.,  0.,  0.],
        [ 0.,  0.,  0.,  0.,  0.]]])
>>>

哈哈,时常更新错误。。。。




0 0
原创粉丝点击