0

I am reading in files containing 238 x 1 feature vectors. Attempting to grab the first 2 numbers in each file to create a 2d plot using numpy. I've got a decent start, just am stuck on how to fill the np array that I want to plot.

import os                # for file handling functions
import numpy as np            # for array/matrix processing
import matplotlib.pyplot as plt        # for general plotting


femaleDataSets = 0
females = []
lists = []
femaleVectors = 0
femaleSizes = 0

filePath = "Dataset/parameter feature vectors"
for fname in os.listdir(filePath):
    index = fname.find("female")   
    if index != -1:
        females.append(index)
        femaleDataSets +=1
        tempFile = open(filePath+"/"+fname, 'rU') # open each female file
        for line in tempFile:
            femaleVectors +=1
            for word in line.split():
                femaleSizes +=1        
                lists.append(word)
                
print "Number of females: ", femaleDataSets
        
femaleData = np.zeros((femaleSizes, femaleVectors))

for j in range(femaleSizes):
    for i in range(femaleVectors):
        femaleData[j, i] = # fill array  
        
plt.hold('on') 
plt.plot(femaleData[0,:],femaleData[1,:],'r+')
plt.title('Female/Male Feature Vectors')
plt.show()
2
Contributors
3
Replies
5
Views
7 Years
Discussion Span
Last Post by bol0gna
0

Sample data file contains:
0.157957
-0.108352
-0.416099
-0.147049
0.194426
-0.0338146
-0.146482
0.0952099

..all the way down to 238 numbers.

I'd like to to go ahead and read them all into 238x1 np arrays. As for plotting, I'd just grab the first 2 numbers as a 2x1 vector for each file.

0

Can someone show me how to go about filling an array using the nested for loops at the bottom.. for just one of my 238 X1 files - just to give me a start?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.