鱼C论坛

 找回密码
 立即注册
查看: 1622|回复: 4

[已解决]什么是矩阵和维度

[复制链接]
发表于 2021-1-24 00:09:30 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
shape(0)和shape(1)代表什么?
最佳答案
2021-1-24 08:48:53
本帖最后由 suchocolate 于 2021-1-24 09:10 编辑

不知道你说的是什么方面的shape函数,如果是numpy,numpy.shape(a)返回的是a的纬度。
>>> import numpy as np
>>> ls1 = [1,2,3,4,5]
>>> np.shape(ls1)
(5,)
>>> ls2 = [[1,2,3,4,5],[6,7,8,9,10]]
>>> np.shape(ls2)
(2, 5)
>>> 
>>> help(np.shape)
Help on function shape in module numpy:

shape(a)
    Return the shape of an array.
    
    Parameters
    ----------
    a : array_like
        Input array.
    
    Returns
    -------
    shape : tuple of ints
        The elements of the shape tuple give the lengths of the
        corresponding array dimensions.
这些基本的东西看教程吧。https://www.runoob.com/numpy/numpy-tutorial.html
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-1-24 08:48:53 | 显示全部楼层    本楼为最佳答案   
本帖最后由 suchocolate 于 2021-1-24 09:10 编辑

不知道你说的是什么方面的shape函数,如果是numpy,numpy.shape(a)返回的是a的纬度。
>>> import numpy as np
>>> ls1 = [1,2,3,4,5]
>>> np.shape(ls1)
(5,)
>>> ls2 = [[1,2,3,4,5],[6,7,8,9,10]]
>>> np.shape(ls2)
(2, 5)
>>> 
>>> help(np.shape)
Help on function shape in module numpy:

shape(a)
    Return the shape of an array.
    
    Parameters
    ----------
    a : array_like
        Input array.
    
    Returns
    -------
    shape : tuple of ints
        The elements of the shape tuple give the lengths of the
        corresponding array dimensions.
这些基本的东西看教程吧。https://www.runoob.com/numpy/numpy-tutorial.html
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-1-24 09:58:15 | 显示全部楼层
建立一个4×2的矩阵c, c.shape[1] 为第一维的长度,c.shape[0] 为第二维的长度
>>> c = array([[1,1],[1,2],[1,3],[1,4]])  
>>> c.shape  
(4, 2)  
>>> c.shape[0]  
4  
>>> c.shape[1]  
2  
那是不是说shape(0)是矩阵中的行数,shape(1)是矩阵中的列数,也相当于二维坐标中的y,x轴,然后好像还有三维,四维。。。。是吧
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-1-24 12:32:46 From FishC Mobile | 显示全部楼层
suchocolate 发表于 2021-1-24 08:48
不知道你说的是什么方面的shape函数,如果是numpy,numpy.shape(a)返回的是a的纬度。
这些基本的东西看教 ...

结合你的答案我理解一下,你看看我说的对吗?
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-1-24 12:41:31 | 显示全部楼层
1476372787 发表于 2021-1-24 12:32
结合你的答案我理解一下,你看看我说的对吗?

差不多,看数据就是行数和列数。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-9-21 10:21

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表