I'm trying to store or arrange three sets of two-dimensional data into three 2xN matrices that are stored as NumPy arrays. - import os # for file handling functions
-
import numpy as np # for array/matrix processing
-
import matplotlib.pyplot as plt # for general plotting
-
from mpl_toolkits.mplot3d import axes3d # for 3d plotting
-
-
wordList=[]
-
numFiles = 0
-
numDataSets = numVectors = sizeVector = 0
-
-
print"\n\nBeginning data processing."
-
# traverse filePath folder
-
filePath = "Train"
-
for file in os.listdir(filePath):
-
numDataSets +=1 # one data set per file
-
print "Loading the file: " + file + "."
-
tempFile = open(filePath+"/"+file, 'rU')
-
for line in tempFile:
-
numVectors +=1 # one vector per line
-
for word in line.split():
-
sizeVector +=1 # components in vector
-
wordList.append(word)
-
-
sizeVector = sizeVector / numVectors
-
numVectors = numVectors / numDataSets
-
-
# print"\nHere's all the data:\n", wordList, "\n\n"
-
print "numDataSets: ",numDataSets
-
print "numVectors: ",numVectors
-
print "sizeVector: ",sizeVector
-
x = eval(wordList[5])
-
-
# Structure our arrays to hold our data.
-
# We'll use the three sample class data sets from the text.
-
# sizeVector of rows and numVectors of columns for column vector data.
-
# In other words, each feature vector will be a column vector for set array.
-
w1 = np.zeros((sizeVector, numVectors))
-
w2 = np.zeros((sizeVector, numVectors))
-
w3 = np.zeros((sizeVector, numVectors))
-
-
# Load matrix array with class w1 numeric values,
-
# replacing elements indexed as in matrices row, col starting from 0.
-
# Pull elements from wordList based on dataSet, sizeVector, and
-
# which vector we're on during the column, row iteration.
-
-
skip = numVectors*sizeVector
-
-
dataSet = 0
-
for j in range(sizeVector):
-
for i in range(numVectors):
-
(do something - nothing I've tried is working)
-
print "\nClass w1 is as follows: \n",w1
-
-
dataSet = 1
-
for j in range(sizeVector):
-
for i in range(numVectors):
-
(do something - nothing I've tried is working)
-
print "\nClass w2 is as follows: \n",w2
-
-
dataSet = 2
-
for j in range(sizeVector):
-
for i in range(numVectors):
-
(do something - nothing I've tried is working)
-
print "\nClass w3 is as follows: \n",w3
I need advice on how to get my dataSet(s) set up in this 2xN format.
1 4928
Hi
This is a bit difficult to engage on, because of the level of detail. You might also get better responses if you say more generally what you're trying to achieve and why.
But, if I understand it, you have a list, called wordList which has (3 x numVectors x sizeVector) elements, and you want to change it into 3 separate numpy arrays each of which has 2 columns and (numVectors x sizeVector)/2 rows. Or, perhaps into arrays which have sizeVector columns and numVectors rows.
So the key lines might be something like
w1[i,j]=wordList[i+numVectors*j]
w2[i,j]=wordList[i+numVectors*j+size]
w2[i,j]=wordList[i+numVectors*j+2*size]
or maybe w1[i][j]
I haven't had a chance to check it yet. Is something like this what you've tried?
Sign in to post your reply or Sign up for a free account.
Similar topics
by: maxwell |
last post by:
I used to program in matlab
An read an image file with :
fread(a,,0)
which gave me a matrix of 256*256 full of numbers which were the pidxel
values from 0 to 256.
How do i do the same in c++
...
|
by: Gaz |
last post by:
Hi guys. I've been lookig for this in the numpy pdf manual, in this
group and on google, but i could not get an answer...
Is there a way to create a custom data type (eg: Name: string(30), Age:...
|
by: lancered |
last post by:
Hi dear all,
I am using Python2.4.2+NumPy1.0.1 to deal with a parameter
estimation problem with the least square methods. During the
calculations, I use NumPy package to deal with matrix...
|
by: James Stroud |
last post by:
Hello All,
I'm using numpy to calculate determinants of matrices that look like
this (13x13):
|
by: devnew |
last post by:
hi
i am looking for some info about mapping btw values in an array and
corresponding columns of a matrix
i have an numpy array=
and a numpy matrix object=
matrix((,
,
,
))
|
by: sapsi |
last post by:
Hello,
I have a numpy array (2 rows 3 colums)
import numpy
a=numpy.array( , ])
I wish to add a row, this is how i do it
s=a.shape
numpy.resize(a,s+1,s)
|
by: Sean Davis |
last post by:
I have a set of numpy arrays which I would like to save to a gzip
file. Here is an example without gzip:
b=numpy.ones(1000000,dtype=numpy.uint8)
a=numpy.zeros(1000000,dtype=numpy.uint8)
fd =...
|
by: arsyed |
last post by:
On Thu, Aug 7, 2008 at 1:36 PM, Simon Parker <simon_ecc@yahoo.co.ukwrote:
You can use numpy:
http://www.scipy.org/NumPy
for example:
In : arr = numpy.char.array()
|
by: Carl Banks |
last post by:
On Sep 22, 4:02 am, Al Kabaila <akaba...@pcug.org.auwrote:
I wouldn't since I do pretty advanced stuff and I'm happy to use numpy
as-is, but I suspect a lot of people would find a convenient...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |