numpy zeros错误-TypeError:np.zeros无法理解数据类型

时间:2019-03-06 13:24:07

标签: python-3.x numpy pickle

   dir_path='/home/jeevitha/8_8_192_features'
    #count = 1
    for name in os.listdir(dir_path):
    #count += 1
    video_id = name.split('.')[0]
    fname='/home/jeevitha/8_8_192_features'+video_id+'.pkl'
    if not (os.path.isfile(fname) ):
        video_file_path=os.path.join(dir_path, name)
        features=open(video_file_path, 'rb')  
        features=list() 
        new_features = np.zeros(8,8,192)
        for i in features:
            new_features+=features[i]
        new_features=new_features/len(features)
        dump(features,open(fname,'wb'))  

请帮助我,使用np.zeros存储泡菜文件

我尝试过 导入数学和numpy 仍然显示错误,例如“无法理解数据类型”

3 个答案:

答案 0 :(得分:0)

应该是

new_features = np.zeros([8,8,192])

编辑: 此代码段还有其他问题。

features=open(video_file_path, 'rb')  
features=list() #remove this. debug code?
new_features = np.zeros(8,8,192)
for i in features:
    new_features+=features[i]
new_features=new_features/len(features)
dump(features,open(fname,'wb')) 

功能设置为空列表并保存。 而且,我想您想保存new_features?

答案 1 :(得分:0)

如果是多个维度,则必须提供一个元组, 参见here

np.zeros((8,8,192))是您想要的,或者np.zeros([8,8,192])如肮脏的袜子所说

答案 2 :(得分:0)

已排序

 dir_path='/home/jeevitha/8_8_192_features'
    #count = 1
    for name in os.listdir(dir_path):
    #count += 1
    video_id = name.split('.')[0]
    fname='/home/jeevitha/8_8_192_features'+video_id+'.pkl'
    if not (os.path.isfile(fname) ):
        video_file_path=os.path.join(dir_path, name)
        features=open(video_file_path, 'rb')  
        features=list() 
        new_features = np.zeros([8,8,192])
        for i in features:
            new_features+=features[i]
        new_features=new_features/len(features)
        dump(new_features,open(fname,'wb'))