0
votes

I want to edit zip file generated by numpy savez function. For example we can make a zip file like

>>> import numpy as np
>>> x = np.array([1,2,3])
>>> y = np.array([4,5,6])
>>> dat = {'/path/to/x': x, '/path/to/y': y}
>>> f = open('foo', 'wb')
>>> np.savez(f, **dat)

This code creates a zip file named foo. (On ubuntu GUI, it is shown as Zip archive type)

Then, I want to remove the file y in the zip file. (Without using Python)

I have tried an approach that first unzip the file and manually remove the file and zip it again. I made a zip file by tar command, but it generates gzip-compressed tar archive.

What is the correct way to edit and generate zip file generated by numpy save_z?

2
if you use unzip then you should check zip command.furas

2 Answers

0
votes

Use the -d option from the zip command like this:

zip foo -d y

This will delete file y from the zip file foo.

You can check the files stored in the zip file with unzip -l foo to check the full path and names of the files stored in foo.

0
votes

I tried this with the archive manager; in my case the Mate version, Engrampa.

I got an error when I tried to delete a file from from a .npz file. But if I renamed it to .zip the delete worked fine. And np.load handled the zip name.

An npz file is p7zip Version 9.20; this is a different archive format than the 'native' unix, gzipped tar. A modern linux archive manager can handle these and others, depending on which commandline tools are installed.