Created
March 12, 2018 22:17
-
-
Save VitorDiToro/96105dcc53e4c85ffa31f10bc182869c to your computer and use it in GitHub Desktop.
This file contains hidden or 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 numpy as np | |
import time | |
def readMatrixFile(FileName): | |
rows,cols=np.fromfile(FileName, dtype=int, count=2, sep=",") | |
a = np.fromfile(FileName, dtype=float, count=rows*cols, sep=" ").reshape((rows,cols)) | |
return a | |
t1 = time.time() | |
vetIN = readMatrixFile('1000000.txt') | |
vet2 = np.zeros(max(vetIN)+1) | |
for i in vetIN: | |
vet2[i] = vet2[i] + 1 | |
for i in range(len(vet2)-1): | |
vet2[i+1] = vet2[i+1] + vet2[i] | |
vetOut = np.zeros(len(vetIN)+1) | |
for i in range(len(vetIN)): | |
vetOut[int(vet2[vetIN[i]])] = vetIN[i] | |
vet2[vetIN[i]] -= 1 | |
t2 = time.time(); | |
print vetOut | |
print "Tempo: " + str(t2-t1); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment