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 4966 Glenton 391
Recognized Expert Contributor
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++
i read with fin.read((char *) &pl sizeof pl)
which brings out the text in the file .
But the matrix of numbers just appears as nothing.
|
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:
int(2), married: boolean, etc) and then use that custom data in a
matrix? Actually, this is a two question question :P
Im doing a simple hex based game and i need a way to store every hex
property (color, owner,x, y, etc) in a matrix's "cell",...
|
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 operations,
mostly matrix inversion and trasposition. The dimentions of the
matrices used are about 29x19,19x19 and 29x29.
During the calculation, I noticed an apparent error of
inverion of a 19x19 matrix. Denote this matrix as KK, U=KK^ -1, I
found...
|
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 = file('test.dat','wb')
a.tofile(fd)
b.tofile(fd)
fd.close()
|
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 basic
matrix library useful.
Your short list covers most of the important stuff.
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |