Created
February 6, 2014 00:41
-
-
Save steveharoz/8836361 to your computer and use it in GitHub Desktop.
Convert npy files to tab delimited tables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import struct | |
import numpy as np | |
import os | |
def parseNPY(path, fileJustName): | |
# load from the file | |
inputFile = os.path.join(path, fileJustName + ".npy") | |
matrices = np.load(inputFile) | |
outputfile = os.path.join(path, fileJustName) | |
for m in range(matrices.shape[0]): | |
# file name for this matrix | |
outFileFull = outputfile + "-" + str(m) + ".txt" | |
# output matrix to a numbered file | |
np.savetxt(outFileFull, matrices[m], fmt="%i", delimiter="\t") | |
mypath = "D:/steveharoz/Documents/Franconeri/numpy/" | |
for path, paths, filenames in os.walk(mypath): | |
# translate all filenames. | |
for filename in filenames: | |
fileJustName, fileExtension = os.path.splitext(filename) | |
if fileExtension == ".npy": | |
print(os.path.join(path, fileJustName)) | |
parseNPY(path, fileJustName) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment