473,543 Members | 1,873 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

lists <-> tuple

I am new to Python and have to create an import library in C that uses
matrices.

These matrices can be one-dimensional (vectors) or two-dimensional. If I
look in the ActivePython 2.4 documentation at data structures, then I see at
least 2 posibilities to represent them: Lists and Tuples.

The documention doesn't give me much information on what the best choice is
for the data type to provide/return these matrices.

So my question is, should I use lists or tuples to represent my matrices in
and why?

Thanks for any reaction.
Nov 2 '05 #1
4 1793
Jim
> Tuples or lists for matrix-like functionality?

Use lists. Tuples are meant for small immutable sets of things that go
together. Lists are more like arrays, and you can assign to one
existing element if you want.

One exception, is a short vector is often a tuple like (x, y, z) and
you might want to multiply that vector by your matrix. You can convert
a tuple to a list with list(aTuple) or back with tuple(aList.)

Even better, take a look at numarray (or numpy or scipy or scipy_core.)
They all have really nice matrix code and there are C APIs that let
you manipulate them. Chances are they do everything you're intending
to implement.

Immutability example:
tup = ("a", "b", "c")
tup[1] = "g"
Traceback (most recent call last):
File "<input>", line 1, in ?
TypeError: object does not support item assignment
lst = ["a", "b", "c"]
lst[1] = "g"
lst
['a', 'g', 'c']
-Jim

Nov 2 '05 #2
Peter Notebaert wrote:
I am new to Python and have to create an import library in C that uses
matrices.

These matrices can be one-dimensional (vectors) or two-dimensional. If I
look in the ActivePython 2.4 documentation at data structures, then I see at
least 2 posibilities to represent them: Lists and Tuples.

The documention doesn't give me much information on what the best choice is
for the data type to provide/return these matrices.

So my question is, should I use lists or tuples to represent my matrices in
and why?


You'll probably want to use scipy_core. It's a package designed
specifically to deal with multidimensiona l arrays of homogeneous,
(usually) numeric data.

http://numeric.scipy.org

--
Robert Kern
rk***@ucsd.edu

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter

Nov 2 '05 #3

"Jim" <mr*****@gmail. com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
Tuples or lists for matrix-like functionality?


Use lists. Tuples are meant for small immutable sets of things that go
together. Lists are more like arrays, and you can assign to one
existing element if you want.

One exception, is a short vector is often a tuple like (x, y, z) and
you might want to multiply that vector by your matrix. You can convert
a tuple to a list with list(aTuple) or back with tuple(aList.)

Even better, take a look at numarray (or numpy or scipy or scipy_core.)
They all have really nice matrix code and there are C APIs that let
you manipulate them. Chances are they do everything you're intending
to implement.

Immutability example:
tup = ("a", "b", "c")
tup[1] = "g"
Traceback (most recent call last):
File "<input>", line 1, in ?
TypeError: object does not support item assignment
lst = ["a", "b", "c"]
lst[1] = "g"
lst
['a', 'g', 'c']
-Jim


Thanks!
Nov 5 '05 #4

"Robert Kern" <ro*********@gm ail.com> wrote in message
news:ma******** *************** **************@ python.org...
Peter Notebaert wrote:
I am new to Python and have to create an import library in C that uses
matrices.

These matrices can be one-dimensional (vectors) or two-dimensional. If I
look in the ActivePython 2.4 documentation at data structures, then I see
at
least 2 posibilities to represent them: Lists and Tuples.

The documention doesn't give me much information on what the best choice
is
for the data type to provide/return these matrices.

So my question is, should I use lists or tuples to represent my matrices
in
and why?


You'll probably want to use scipy_core. It's a package designed
specifically to deal with multidimensiona l arrays of homogeneous,
(usually) numeric data.

http://numeric.scipy.org

--
Robert Kern
rk***@ucsd.edu

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter


Thanks!
Nov 5 '05 #5

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

Similar topics

9
3736
by: Dave H | last post by:
Hello, I have a query regarding definition lists. Is it good practice semantically to use the dt and dd elements to mark up questions and answers in a frequently asked questions list, or FAQ? Here is an example of just such a usage: <dl class="faq"> <di>
41
3902
by: Odd-R. | last post by:
I have to lists, A and B, that may, or may not be equal. If they are not identical, I want the output to be three new lists, X,Y and Z where X has all the elements that are in A, but not in B, and Y contains all the elements that are B but not in A. Z will then have the elements that are in both A and B. One way of doing this is of course...
3
1640
by: Gary Smith | last post by:
Hi, I've got a field that contains a list of rooms. In most cases, this contains a single ID. However, under some circumstances, the field may contain a list of two IDs which are broken by a comma. For example: BENL LT, RAT LT At the moment, I've got the VBA bits working on the single ID stuff, but, should it come across a list like...
3
3258
by: s_subbarayan | last post by:
Dear all, 1)In one of our implementation for an application we are supposed to collate two linked lists.The actual problem is like this: There are two singularly linked lists, the final output will be a "perfectly shuffle" of the lists together into a single list. The new list should consist of consecutively alternating nodes from both...
10
42934
by: Jon Noring | last post by:
Out of curiosity, may a CDATA section appear within an attribute value with datatype CDATA? And if so, how about other attribute value datatypes which accept the XML markup characters? To me, the XML specification seems a little ambiguous on this, so I defer to the XML authorities. Refer to sections 2.4 and 2.7 (it all hinges on if CDATA...
16
2576
by: Michael M. | last post by:
How to find the longst element list of lists? I think, there should be an easier way then this: s1 = s2 = s3 = if len(s1) >= len(s2) and len(s1) >= len(s3): sx1=s1 ## s1 ist längster
51
8579
by: Joerg Schoen | last post by:
Hi folks! Everyone knows how to sort arrays (e. g. quicksort, heapsort etc.) For linked lists, mergesort is the typical choice. While I was looking for a optimized implementation of mergesort for linked lists, I couldn't find one. I read something about Mcilroy's "Optimistic Merge Sort" and studied some implementation, but they were for...
14
6120
by: phillipwei | last post by:
What's the best way to achieve this, or is this a bad idea?
48
2349
by: coool | last post by:
Hi I'm now trying to have a dependent lists in a form my form is a query based form i.e. I fill my MySQL query from this form I have around 30 fields/columns
3
3990
by: webmasterATflymagnetic.com | last post by:
Folks, I'm struggling to put the question together, but I have this problem. I have written an HTML form that I can use for data entry. This uses PHP to write a SQL UPDATE command that gets written to my MySQL database. I can later view this data back in the form. One thing I've noticed happening is if I enter code such as &lt; it gets...
0
7411
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...
0
7354
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...
0
7594
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. ...
1
7354
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...
0
7693
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5282
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...
0
3394
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
978
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
643
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...

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.