numpy.loadtxt - python examples

Here are the examples of the python api numpy.loadtxt taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

145 Examples 7

3 View Complete Implementation : merger_methods.py
Copyright MIT License
Author : djp42
def findMergeEventRanges(filepath, LaneCol, MergeLane, VIDCol, FrameCol, TotFrameCol):
    #This will find, for each VID that merges, the start and end frames
    Data = np.loadtxt(filepath+'.txt')
    Firsts = findFirstInstances(Data, VIDCol)  
    Mergers = Firsts[Firsts[:,LaneCol]==MergeLane]
    Starts = Mergers[:,FrameCol]
    Ends = Starts + Mergers[:,TotFrameCol]
    Ends.shape=(len(Ends),1)
    IDStarts = Mergers[:,[VIDCol,FrameCol]]
    Ranges = np.append(IDStarts, Ends, axis=1)
    return Ranges

3 View Complete Implementation : merger_methods.py
Copyright MIT License
Author : djp42
def doMinRangesAndStartForMerges(filepath, LaneCol, VIDCol, FrameCol, TotFrameCol, MergeLane=7):
    Data = np.loadtxt(filepath+'.txt')
    Firsts = findFirstInstances(Data, VIDCol)  
    Mergers = Firsts[Firsts[:,LaneCol]==MergeLane]
    saveArrayTxt(filepath+'-mergerStartTrajectories'+'.txt', Mergers)
    print ("Start trajectories done.")
    Starts = Mergers[:,FrameCol]
    Ends = Starts + min(Mergers[:,TotFrameCol])
    Ends.shape=(len(Ends),1)
    IDStarts = Mergers[:,[VIDCol,FrameCol]]
    Ranges = np.append(IDStarts, Ends, axis=1)
    saveArrayTxt(filepath+'-mergerMinRanges'+'.txt', Ranges)
    print ("Merge ranges done.")

3 View Complete Implementation : learn_util.py
Copyright MIT License
Author : djp42
def makeTrainTestData(filename, portionTrain, seed=None):
    # example filename="res/101_trajectories/aug_trajectories-0750am-0805am.txt"
    #filepath = makePathMR(filename, '-mergerMinRanges')
    filepath = makeFullPath(filename, '-mergerRanges.txt')
    MR = np.loadtxt(filepath, dtype='int')
    traintest = [[],[]]
    random.seed(seed)
    if not numUsing == 0:
        MR = MR[:numUsing]
    for row in MR:
        traintest[random.random() > portionTrain].append(row[0])
    train = traintest[0]
    test = traintest[1]
    filepathTrain = makeFullPath(filename, 'trainIDs.txt')
    filepathTest = makeFullPath(filename, 'testIDs.txt')
    np.savetxt(filepathTrain, train)
    np.savetxt(filepathTest, test)
    return train, test

3 View Complete Implementation : program.py
Copyright MIT License
Author : djp42
def loadScores(score_folder = c.PATH_TO_SCORES, models=["LSTM_128x2"], testnums=["000"], dist_hist=False):
    scores = {}
    for testnum in testnums:
        scores[testnum] = {}
        for model in models:
            filepath = os.path.join(score_folder, str(testnum), model)
            if not dist_hist:
                accuracy = np.loadtxt(filepath + "accuracy.txt")
                score = np.loadtxt(filepath + "score.txt")
                scores[testnum][model] = (accuracy, score)
            else:
                accuracies = np.loadtxt(filepath + "accuracies")
                counts = np.loadtxt(filepath + "counts")
                scores[testnum][model] = (accuracies, counts)
    return scores

3 View Complete Implementation : program.py
Copyright MIT License
Author : djp42
def load_fids(load_folder):
    allFids = []
    secFids = {}
    for subdir, dirs, files in os.walk(load_folder):
        for sub_folder in dirs:
            if len(sub_folder) > 1:
                continue
            i = int(sub_folder)
            fullpath = os.path.join(load_folder, sub_folder, "Fids")
            secFids[i] = np.loadtxt(fullpath)
            allFids.extend(secFids[i])
    return secFids, allFids

3 View Complete Implementation : learn_util.py
Copyright MIT License
Author : djp42
def readExampleData(filename, mean_centered, predict):
    filepath_Xtrain = makeFullPath(filename, '-Xtrain'+str(mean_centered))
    Xtrain = loadSparse(filepath_Xtrain)
    print("Xtrain loaded.",time.ctime())
    filepath_Xtest = makeFullPath(filename, '-Xtest'+str(mean_centered))
    Xtest = loadSparse(filepath_Xtest)
    print("Xtest loaded.",time.ctime())
    filepath_ytrain = makeFullPath(filename, '-ytrain'+str(mean_centered)+predict)
    ytrain = np.loadtxt(filepath_ytrain)
    print("ytrain loaded.",time.ctime())
    filepath_ytest = makeFullPath(filename, '-ytest'+str(mean_centered)+predict)
    ytest = np.loadtxt(filepath_ytest)
    print("ytest loaded.",time.ctime())
    return Xtrain, ytrain, Xtest, ytest

3 View Complete Implementation : eval_util.py
Copyright MIT License
Author : djp42
def getFeatures(folderpath, model_type, fwd_bkwd=None):
    files = filenames()
    if folderpath == "":
        folderpath = files.default_path
    strFwdBkwd = ""
    if fwd_bkwd:
        strFwdBkwd = fwd_bkwd
    if fwd_bkwd and not "LSTM" in model_type:
        features = np.concatenate([np.loadtxt(folderpath + str(i) + os.sep + files.featureString) for i in range(5)])
    elif "LSTM" in model_type:
        features = np.load(folderpath + model_type + os.sep + strFwdBkwd + files.LSTMFeatures)
        print("features from:", str(folderpath + model_type + os.sep + strFwdBkwd + files.LSTMFeatures))
        #features = np.reshape(features, (features.shape[0]*features.shape[1], features.shape[2]))
    else: #not fwd bkwd, just getting one featureset?
        features = np.loadtxt(folderpath + files.featureString)
    return features

3 View Complete Implementation : score_util.py
Copyright MIT License
Author : djp42
def getFeatures(folderpath, model_type, fwd_bkwd=None):
    files = filenames()
    if folderpath == "":
        folderpath = files.default_path
    strFwdBkwd = ""
    if fwd_bkwd:
        strFwdBkwd = fwd_bkwd
    if fwd_bkwd and not "LSTM" in model_type:
        features = np.concatenate([np.loadtxt(
                os.path.join(folderpath, str(i), files.featureString)
            ) for i in range(5)])
    elif "LSTM" in model_type:
        fpath = os.path.join(folderpath, model_type, strFwdBkwd + files.LSTMFeatures)
        features = np.load(fpath)
        print("features from:", fpath)
        #features = np.reshape(features, (features.shape[0]*features.shape[1], features.shape[2]))
    else: #not fwd bkwd, just getting one featureset?
        features = np.loadtxt(os.path.join(folderpath, files.featureString))
    return features

3 View Complete Implementation : merger_methods.py
Copyright MIT License
Author : djp42
def findMergeEventRangesMin(filepath, LaneCol, MergeLane, VIDCol, FrameCol, TotFrameCol):
    #This will find, for each VID that merges, the start and end frames based on the minimum number of frames any merge appears in
    print("Reading data for event range minimums from:",filepath)
    Data = np.loadtxt(filepath+'.txt')
    print("Done reading data for event range minimums from:",filepath)
    Firsts = findFirstInstances(Data, VIDCol)  
    Mergers = Firsts[Firsts[:,LaneCol]==MergeLane]
    Starts = Mergers[:,FrameCol]
    Ends = Starts + min(Mergers[:,TotFrameCol])
    Ends.shape=(len(Ends),1)
    IDStarts = Mergers[:,[VIDCol,FrameCol]]
    Ranges = np.append(IDStarts, Ends, axis=1)
    return Ranges

3 View Complete Implementation : merger_methods.py
Copyright MIT License
Author : djp42
def findAndSaveMergerStartTrajectories(filepath, VIDCol, LaneCol, MergeLane):
    print("Reading data for start trajectories from:",filepath)
    Data = np.loadtxt(filepath+'.txt')
    print("Done reading data for start trajectories from:",filepath)
    Firsts = findFirstInstances(Data, VIDCol)    
    Mergers = Firsts[Firsts[:,LaneCol]==MergeLane]
    saveArrayTxt(filepath+'-mergerStartTrajectories'+'.txt', Mergers)