python数据分析基础知识之shape()函数的使用教程
作者:sodaloveer 时间:2023-06-11 04:03:56
python中shape()函数
shape函数是numpy.core.fromnumeric中的函数,它的功能是读取矩阵的长度。
1、shape()输入参数
(1)参数是个数时,返回空
(2)参数是一维矩阵
(3)参数是二维矩阵
2、判断数组的维度
有几个中括号就为几维数组
shape()中有3个数。
a = np.array([1,2]) #a.shape值(2,),意思是一维数组,数组中有2个元素。
b = np.array([[1],[2]]) #b.shape值是(2,1),意思是一个二维数组,每行有1个元素。
c = np.array([[1,2]]) #c.shape值是(1,2),意思是一个二维数组,每行有2个元素。
使用shape[0]读取矩阵第一维度的长度,即行数;使用shape[1]读取矩阵第二维度的长度,即列数。
import numpy as np
x = np.array([[1,2,5],[2,3,5],[3,4,5],[2,3,6]])
#输出数组的行和列数
print x.shape #结果: (4, 3)
#只输出行数
print x.shape[0] #结果: 4
#只输出列数
print x.shape[1] #结果: 3
3、shape()中“?”的含义
而在debug相关程序时,可能会出现shape(?,2,3)这便代表数组每一个都是2行3列的,前面这个“?”便代表批处理个数,若为1则有1个,为2则有两个,但是在debug的时候不知道有几个,所以以“?”的形式显示。
来源:https://blog.csdn.net/sodaloveer/article/details/125320740
标签:python,shape函数
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python排序搜索基本算法之堆排序实例详解
2021-07-10 12:35:30
![](https://img.aspxhome.com/file/2023/9/103609_0s.png)
在PyCharm中实现添加快捷模块
2023-04-22 11:30:58
![](https://img.aspxhome.com/file/2023/4/66384_0s.jpg)
利用pyshp包给shapefile文件添加字段的实例
2023-08-12 15:48:38
Mysql 存储过程中使用游标循环读取临时表
2024-01-28 00:55:20
Python实现动态条形图绘制的示例代码
2021-09-25 03:05:17
![](https://img.aspxhome.com/file/2023/8/72098_0s.jpg)
MySQL数据库的23个特别注意事项
2010-08-08 14:43:00
Python 中数组和数字相乘时的注意事项说明
2023-02-15 19:38:48
如何运行Python程序的方法
2023-01-13 07:56:03
![](https://img.aspxhome.com/file/2023/6/86686_0s.jpg)
Python找出list中最常出现元素的方法
2022-10-31 14:24:38
python的ImageTk.PhotoImage大坑及解决
2021-02-24 13:53:04
oracle移植到mysql注意事项
2008-12-25 13:09:00
将SQL Server中所有表的列信息显示出来
2009-01-08 16:27:00
Python Pandas基础操作详解
2022-02-18 11:17:07
Python如何telnet到网络设备
2023-11-20 09:47:45
![](https://img.aspxhome.com/file/2023/4/112984_0s.gif)
Go语言文件开关及读写操作示例
2023-08-05 19:47:27
浅谈Python实现Apriori算法介绍
2021-09-14 19:10:22
![](https://img.aspxhome.com/file/2023/9/115729_0s.png)
JS实现选择TextArea内文本的方法
2024-04-16 10:40:02
Python数组条件过滤filter函数使用示例
2021-06-11 15:10:51
浅谈对Python变量的一些认识理解
2021-06-10 05:06:52
![](https://img.aspxhome.com/file/2023/7/127247_0s.png)
python计算机视觉opencv卡号识别示例详解
2023-04-14 13:58:25
![](https://img.aspxhome.com/file/2023/6/105306_0s.png)