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:
        femaleDataSets +=1
        tempFile = open(filePath+"/"+fname, 'rU') # open each female file
        for line in tempFile:
            femaleVectors +=1
            for word in line.split():
                femaleSizes +=1        
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.title('Female/Male Feature Vectors')

Recommended Answers

All 3 Replies

Can you give us a short example what your data file looks like and what you want to extract?

Sample data file contains:

..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.

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?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.