“列表"对象没有属性“形状" [英] 'list' object has no attribute 'shape'

查看:95
本文介绍了“列表"对象没有属性“形状"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何创建一个数组到numpy数组?

how to create an array to numpy array?

def test(X, N):
    [n,T] = X.shape
    print "n : ", n
    print "T : ", T



if __name__=="__main__":

    X = [[[-9.035250067710876], [7.453250169754028], [33.34074878692627]], [[-6.63700008392334], [5.132999956607819], [31.66075038909912]], [[-5.1272499561309814], [8.251499891281128], [30.925999641418457]]]
    N = 200
    test(X, N)

我收到错误消息

AttributeError: 'list' object has no attribute 'shape'

那么,我想我需要将X转换为numpy数组吗?

So, I think I need to convert my X to numpy array?

推荐答案

使用 使用shape属性.

>>> import numpy as np
>>> X = np.array([
...     [[-9.035250067710876], [7.453250169754028], [33.34074878692627]],
...     [[-6.63700008392334], [5.132999956607819], [31.66075038909912]],
...     [[-5.1272499561309814], [8.251499891281128], [30.925999641418457]]
... ])
>>> X.shape
(3L, 3L, 1L)

注意 X.shape返回给定数组的3项元组; [n, T] = X.shape引发ValueError.

NOTE X.shape returns 3-items tuple for the given array; [n, T] = X.shape raises ValueError.

这篇关于“列表"对象没有属性“形状"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆