473,804 Members | 3,686 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 8953

"CC" <ch*******@gmai l.com> wrote in message
news:11******** **************@ j55g2000cwa.goo glegroups.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(l60 00)

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*******@gmai l.com> wrote in message
news:11******** **************@ j55g2000cwa.goo glegroups.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(l60 00)

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.ListVie w and pyarray.ArrayVi ew 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**@telcopart ners.com> wrote in message
news:e4******** **@sea.gmane.or g...
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**@telcopart ners.com> wrote in message
news:e4******** **@sea.gmane.or g...
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
2131
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 include arrays as object member? And how is it declared in the PyMemberDef array? If you can not use C arrays, I thought perhaps then I should use Python
63
5196
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 aware of any scripting language that could be considered as "Python minus OO stuff"? (As you can see I'm completely new to Python and initially believed it's a nice&simple scripting language before seeing all this OO stuff that was added in over...
54
3992
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 but *NOT* mystring (5th element). Many people don't like idea that 5th element is not invited. (BTW, yes I'm aware of the explanation where slicing
5
1639
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 find some bugs). I had a few questions while writing this as well. Also, I know that there are much better ways to compute nearest neighbors than the brute force n^2 method, but this is plenty fast for this application (at least the C version...
10
12763
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 != colIndex2) { for (var i = 0; i < table.rows.length; i++) { var row = table.rows; var cell1 = row.cells; var cell2 = row.cells;
11
3789
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 appreciate it: 1. What exactly is a Python list? If one writes a, then is the complexity Theta(n)? If this is O(1), then why was the name "list" chosen? If this is indeed Theta(n), then what alternative should be used? (array does not seem suited for...
1
3394
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 this case the user is defining the necessary number of columns. Specifically, I have vb project that effectively gathers the scoring information for a soccer team and outputs it to a listbox. The gamedate array would be the first row, and the...
0
3090
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 simulation into Numpy arrays and do a simple calculation on them that involves a few eigenvalues of small matricies and quite a number of temporary arrays. I had assumed that that generating lots of temporary arrays would make my program run slowly,...
3
3921
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", "copyright", "credits" or "license" for more information. False
0
9706
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, 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...
0
9582
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,...
0
10580
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10335
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 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...
1
10323
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,...
1
7621
isladogs
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4301
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3821
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2993
bsmnconsultancy
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...

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.