Alessandro Minervini
Alessandro Minervini

Reputation: 123

Open npy.gz file on python

I want to extract the .npy file from a .gz compressed with gzip and numpy. I'm using Python 3.6:

import gzip
import numpy as np

f = gzip.GzipFile('mydataset.npy.gz', "r")
a = np.load(f)

The error found:

raise OSError('Not a gzipped file (%r)' % magic) OSError: Not a gzipped file (b'\x93N')

Upvotes: 0

Views: 1303

Answers (1)

Jean-François Fabre
Jean-François Fabre

Reputation: 140158

your file is just a .npy file, not a .gz file

From the documentation

The first 6 bytes are a magic string: exactly \x93NUMPY.

So remove the .gz extension and load it without gzip module passing the name directly as load supports it, you'll be fine.

After renaming:

a = np.load('mydataset.npy')

Upvotes: 2

Related Questions