Search code examples
pythonlistnetcdfsift

ValueError: object too deep for desired array (netcdf)


I am trying to pass SIFT features to netcdf file but when I tried to do then it shows me following error(I am using Ubuntu 15.10 and coding in python).

File "/home/Research/netcdf_helpers.py", line 15, in createNcVar nc_var.assignValue(data) ValueError: object too deep for desired array

I searched various solutions but still finding the correct solution for this.

Current format of my data structure is as follows:

[[(file1feature1,file1feature2,file1feature3,file1feature4,file1feature5),(file2feature1,file2feature2,file2feature3,file2feature4,file2feature5)(file3feature1,file3feature2,file3feature3,file3feature4,file3feature5)]]

The desired output I am looking to achieve is as follows:

[file1feature1,file1feature2,file1feature3,file1feature4,file2feature5,file2feature1,file2feature2,file2feature3,file2feature4.......]

I have consumed half of my day for correcting this error but still struggling. Any help would be highly appreciated.


Solution

  • Example:

    In order to mimic your data structure I used following data:

    raw_data = [[(1, 2, 3), (9, 8, 7), (5, 6, 0)]]]  # this is the raw data
    

    Following operation achieves the structure you are after:

    data = () # place holder for your filtered data
    
    for entry in raw_data[0]:  # operation
        data += entry
    

    Output:

    print(list(data)) # [1, 2, 3, 9, 8, 7, 5, 6, 0]