【问题标题】:numpy zeros error - TypeError: data type not understood for np.zerosnumpy zeros 错误 - TypeError:np.zeros 无法理解数据类型
【发布时间】:2019-03-06 13:24:06
【问题描述】:
   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 仍然显示“数据类型不理解”之类的错误

【问题讨论】:

    标签: python-3.x numpy pickle


    【解决方案1】:

    如果有多个维度,您必须提供一个元组, 见here

    np.zeros((8,8,192)) 是你想要的,或者 np.zeros([8,8,192]) 就像 filthysocks 所说的

    【讨论】:

    • 其实 8,8,192 是用来存储图片的 pickle 文件的形状,两种格式的结果都和 (0,) 一样
    【解决方案2】:

    它已排序,

     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'))
    

    【讨论】:

      【解决方案3】:

      应该是

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

      编辑: 这个 sn-p 还有更多问题。

      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')) 
      

      features 设置为空列表并保存。 此外,我猜你想保存 new_features?

      【讨论】:

      • new_features = np.zeros([8,8,192]) 如果我按照上面的代码运行,泡菜特征形状显示 (0,),而不是来自泡菜导入加载的 (8,8,192) features=load(open('/home/jeevitha/8_8_192_features_mean/0lh_UWF9ZP4_148_155.pkl','rb')) feat=np.array(features) print(feat.shape)
      • 不知道其余代码的作用,但它确实对我有用:zeros = np.zeros([8,8,192]) pickle.dump(zeros, open('/tmp/uiae', 'wb')) x = pickle.load(open('/tmp/uiae', 'rb')) x.shape Out[51]: (8, 8, 192)
      猜你喜欢
      • 1970-01-01
      • 2017-09-24
      • 2020-02-01
      • 2021-02-11
      • 1970-01-01
      • 2022-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多