473,387 Members | 1,431 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to add columns to python arrays

CC
Hi there,

I wanna compile a 6000x1000 array with python. The array starts from
'empty', each time I get a 6000 length list, I wanna add it to the
exist array as a column vector. Is there any function to do so?

Or, I can add the list as a rows, if this is easier, and transpose the
whole array after all the rows are setup.

Thanks so much.

May 17 '06 #1
4 8929

"CC" <ch*******@gmail.com> wrote in message
news:11**********************@j55g2000cwa.googlegr oups.com...
I wanna compile a 6000x1000 array with python. The array starts from
'empty', each time I get a 6000 length list, I wanna add it to the
exist array as a column vector. Is there any function to do so?

Or, I can add the list as a rows, if this is easier, and transpose the
whole array after all the rows are setup.


Python does not come with a 2D array type either as a builtin type or as a
standard library module. You can only simulate one with a sequence of
sequences (list of lists, for instance). You could initialize as follows:

aray = []
for l6000 in source(): aray.append(l6000)

While this will print as a list of rows, you are free to think of it as a
list of columns.

That said, I suspect you should use the 3rd party NumPy package which
defines multiple-dimensional arrays of several base types.

Terry Jan Reedy

May 17 '06 #2
Terry Reedy wrote:
"CC" <ch*******@gmail.com> wrote in message
news:11**********************@j55g2000cwa.googlegr oups.com...
I wanna compile a 6000x1000 array with python. The array starts from
'empty', each time I get a 6000 length list, I wanna add it to the
exist array as a column vector. Is there any function to do so?

Or, I can add the list as a rows, if this is easier, and transpose the
whole array after all the rows are setup.


Python does not come with a 2D array type either as a builtin type or as a
standard library module. You can only simulate one with a sequence of
sequences (list of lists, for instance). You could initialize as follows:

aray = []
for l6000 in source(): aray.append(l6000)

While this will print as a list of rows, you are free to think of it as a
list of columns.

That said, I suspect you should use the 3rd party NumPy package which
defines multiple-dimensional arrays of several base types.

Terry Jan Reedy

If you're just looking for a multi-dimensional array type, and don't need
maximum speed or the vast range of array-processing that numpy offers, then
*pyarray* provides a pure-python single module solution.

the latest pyarray is available with tests and documentation at:
http://svn.brownspencer.com/pyarray/trunk/

Introduction
============
pyarray is a pure-Python implementation of a multi-dimensional array type.

pyarray.ListView and pyarray.ArrayView offer a substantial subset of
numpy.ArrayType functionality, by wrapping standard python 'list' and
'array.array' respectively.

Key features include:
* Views: all subscripting operations apart from individual cell access
access return views to existing 'live' data
* Extended Indexing: slicing, arbitrary 'takes', index arrays etc...
* Unlimited re-shaping: while still addressing one data-source
* Elementwise binary operations: all basic arithmetic and comparison
operations
* Data broadcasting: allows assignment and binary operations between
views of different shapes
* Friendly __repr__: work safely with big arrays at the interactive prompt

Regards
Michael
May 17 '06 #3

"Michael Spencer" <ma**@telcopartners.com> wrote in message
news:e4**********@sea.gmane.org...
If you're just looking for a multi-dimensional array type, and don't need
maximum speed or the vast range of array-processing that numpy offers,
then
*pyarray* provides a pure-python single module solution.

the latest pyarray is available with tests and documentation at:
http://svn.brownspencer.com/pyarray/trunk/


Nice. I downloaded and expect to give it a try sometime. I suggest
putting the url in the module file itself to make it easier to search for
updated versions ;-)

tjr

May 17 '06 #4
Terry Reedy wrote:
"Michael Spencer" <ma**@telcopartners.com> wrote in message
news:e4**********@sea.gmane.org...
If you're just looking for a multi-dimensional array type, and don't need
maximum speed or the vast range of array-processing that numpy offers,
then
*pyarray* provides a pure-python single module solution.

the latest pyarray is available with tests and documentation at:
http://svn.brownspencer.com/pyarray/trunk/


Nice. I downloaded and expect to give it a try sometime. I suggest
putting the url in the module file itself to make it easier to search for
updated versions ;-)

tjr

Thanks for the suggestion, Terry. I've added a static link in each source file
to the repository at: http://svn.brownspencer.com/pyarray/
and also added an email address. If you do try it, I'd be interested to hear
your feedback.

Michael

May 17 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: William Hanlon | last post by:
Hi, I would like to use the Python C API to use python to access functions originally written in C. The objects that I would like to pass to python have multi-dimensional arrays. How do I...
63
by: Davor | last post by:
Is it possible to write purely procedural code in Python, or the OO constructs in both language and supporting libraries have got so embedded that it's impossible to avoid them? Also, is anyone...
54
by: seberino | last post by:
Many people I know ask why Python does slicing the way it does..... Can anyone /please/ give me a good defense/justification??? I'm referring to why mystring gives me elements 0, 1, 2 and 3...
5
by: jeremy.d.brewer | last post by:
Hi, I'm rather new to Python, and I've just written my first Python C module. I was wondering if some more experience Pythonista would look over what I've written and given me some pointers (or...
10
by: VA | last post by:
I got the following function to swap table columns from somewhere on the Internet function swapColumns (table, colIndex1, colIndex2) { if (table && table.rows && table.insertBefore && colIndex1...
11
by: efrat | last post by:
Hello, I'm planning to use Python in order to teach a DSA (data structures and algorithms) course in an academic institute. If you could help out with the following questions, I'd sure...
1
by: captainphoenix | last post by:
all in vb2005 I have three arrays: one 2d array, two 1d arrays. I need to output them into a listbox and align them to columns, which I know how to do using string.format(blahblahblah). However, in...
0
by: greg.novak | last post by:
I am using Python to process particle data from a physics simulation. There are about 15 MB of data associated with each simulation, but there are many simulations. I read the data from each...
3
by: Tim Chase | last post by:
Not sure what's going on here and hoping for some insight: tim@rubbish:~$ echo $COLUMNS 129 tim@rubbish:~$ python2.5 Python 2.5.2 (r252:60911, May 28 2008, 08:35:32) on linux2 Type "help",...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
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...
0
jinu1996
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.