shape函数是numpy.core.fromnumeric中的函数,它的功能是读取矩阵的长度,比如shape[0]就是读取矩阵第一维度的长度。它的输入参数可以使一个整数表示维度,也可以是一个矩阵。这么说你可能不太理解,我们还是用各种例子来说明他的用法:

  1. 一维矩阵[1]返回值为(1L,)

    >>> z.shape
    (1,)

  2. 二维矩阵,返回两个值

    >>> m = np.zeros((2,3))
    >>> m.shape
    (2, 3)

  3. 一个单独的数字,返回值为空 

    >>> m = np.zeros(0)
    >>> m.shape
    (0,)

  4. 我们还可以将shape作为矩阵的方法来调用,下面先创建了一个单位矩阵y

    >>> y = np.zeros((2,3,4))
    >>> y
    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.]]])

  5. 我们可以快速读取y的形状       

    >>> y.shape
    (2, 3, 4)

  6. 假如我们只想读取y的维度,如下所示:  

    >>> z.shape[0]
    1
    >>> y.shape[0]
    2
    >>> y.shape[-1]
    4
    >>> y.shape[-2]
    3
    >>> y.shape[2]
    4
    >>> y.shape[1]

numpy中函数shape的用法的更多相关文章

  1. python 中numpy中函数hstack用法和作用

    定义: Stack arrays in sequence horizontally (column wise). Take a sequence of arrays and stack them ho ...

  2. 【python】numpy中的shape用法

    转自 https://blog.csdn.net/u010758410/article/details/71554224# shape函数是numpy.core.fromnumeric中的函数,它的功 ...

  3. Numpy中的shape和reshape()

    shape是查看数据有多少行多少列reshape()是数组array中的方法,作用是将数据重新组织 1.shape import numpy as np a = np.array([1,2,3,4,5 ...

  4. 数据库ORACLE中函数decode的用法

    Decode函数与一系列嵌套的 IF-THEN-ELSE语句相似 decode()函数简介: 使用方法: Select decode(columnname,值1,翻译值1,值2,翻译值2,...值n, ...

  5. Matlab 中 函数circshift()的用法

    a = [ ; ; ]; b = [- - -; - - -;- - -]; c = [ ; ; ]; Hist(:,:,) = a; Hist(:,:,) = b; Hist(:,:,) = c; ...

  6. string.h文件中函数用法

    下面为string.h文件中函数的详细用法: strcpy函数名:strcpy功 能: 拷贝一个字符串到另一个用 法: char *strcpy(char *destin, char *source) ...

  7. pytorch与numpy中的通道交换问题

    pytorch网络输入图像的格式为(C, H, W),而numpy中的图像的shape为(H,W,C) 所以一般需要变换通道,将numpy中的shape变换为torch中的shape. 方法如下: # ...

  8. Python中numpy.apply_along_axis()函数的用法

    numpy.apply_along_axis(func, axis, arr, *args, **kwargs): 必选参数:func,axis,arr.其中func是我们自定义的一个函数,函数fun ...

  9. Numpy中Meshgrid函数介绍及2种应用场景

    近期在好几个地方都看到meshgrid的使用,虽然之前也注意到meshgrid的用法.但总觉得印象不深刻,不是太了解meshgrid的应用场景.所以,本文将进一步介绍Numpy中meshgrid的用法 ...

随机推荐

  1. CentOSmini安装gcc8.2

    一. 如果遇到类似问题: configure: error: in `/usr/local/src/gcc-8.2.0/temp': configure: error: no acceptable C ...

  2. .net webapi 接收 xml 格式数据的三种情况

    webapi 接收 xml 的三种方法 前段时间接到一个任务写一个小接口,要接收java端返回过来的短信xml数据. 刚拿到项目,我的第一想法是对方会以什么形式发送xml格式的数据给我呢,设想三种情况 ...

  3. Leetcode - 517 Super Washing Machines

    今天开始定期记录本人在leetcode上刷题时遇到的有意思的题目.   517. Super Washing Machines   You have n super washing machines ...

  4. 1,fiddler的工作原理和安装

    1,工作原理就是通过设置代理监控客户端和服务端的协议 2,fiddler的安装 1,官方的下载地址:https://www.telerik.com/download/fiddler 一步步安装即可 2 ...

  5. Isight 命令行运行任务

    说明书参考:https://abaqus-docs.mit.edu/2017/English/DSSIMULIA_Established.htm 不一定对版本.但是大部分还可以. 不对的可以在命令里敲 ...

  6. 树莓派3 开机自启动(SPI)

    转自:https://www.raspberrypi-spy.co.uk/2014/08/enabling-the-spi-interface-on-the-raspberry-pi/ 方案一:图形界 ...

  7. postgresql 日期生成流水号

    --表结构 DROP TABLE if exists public.sys_tabid; CREATE TABLE public.sys_tabid ( id serial NOT NULL , ty ...

  8. 1123. Is It a Complete AVL Tree (30)

    An AVL tree is a self-balancing binary search tree. In an AVL tree, the heights of the two child sub ...

  9. CODEFORCES ROUND #740 ANALYSES BY TEAM:RED & BLACK

    A.Alyona and copybooks Problems: 给你一个数n和代价分别为a, b, c.数量不限的1, 2, 3,求将n凑成4的倍数的最小代价 Analysis: cj:取个模随便凑 ...

  10. 移动端各种滚动场景需求的插件better-scroll

    移动端各种滚动场景需求的插件: 文档地址: better-scroll:https://ustbhuangyi.github.io/better-scroll/doc/zh-hans/#better- ...