0

I'm trying to create numpy array and data keys are positions, metadata. Its output should be like below

#sample output
['positions', metadata] #data keys when I print file_name.keys()
{'num_pos': 10, 'keypoints': [[4, 5, 6, 10, 11, 12], [1, 2, 3, 13, 14, 15]]} #values of metadata in dictionary when I print file_name['metadata']

I want output same as above. Below is my python code to get required npz file.

#code sample
positions = [] #this step is working and values are saved in npz file, so I'm just skipping this step, my problem is in metadata key which is given below
metadata = {
'num_pos': 10,
'keypoints': [[4, 5, 6, 10, 11, 12], [1, 2, 3, 13, 14, 15]]
}

positions = np.array(positions).astype(np.float32)
np.savez_compressed('file_name.npz', position=positions, metadata=metadata)

With above code I can get npz file having values of positions but not values of metadata. When I print file_name.keys() then output is ['positions', 'metadata'] which is ok but when I print file_name['metadata'] I'm getting following error.

ValueError: unsupported pickle protocol: 3

Looking for valuable suggestions

Erric
  • 123
  • 1
  • 10
  • You example doesn't give me the error you're reporting. You're currently missing a comma after your filename in the save call, but that raises a SyntaxError. Could you tweak your example to reproduce the error? – PirateNinjas Jul 02 '20 at 10:22
  • I just edit it. I got the point that its problem is due to different protocols in Python 3 and 2. I'm saving npz file in Python 3 but I need to use it in Python 2 project. I think this is the main problem. I got this [this link](https://stackoverflow.com/questions/25843698/valueerror-unsupported-pickle-protocol-3-python2-pickle-can-not-load-the-file) but its for pickle not for npz and I'm unable to find right protocol for numpy array to save npz file in Python 3 that can also be used in Python 2. Could you help me regarding this problem? – Erric Jul 02 '20 at 10:26

0 Answers0