473,783 Members | 2,350 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 1802
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
3752
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
3964
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 to iterate throug the lists and compare each of the element, but is there a more efficient way? ...
3
1656
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 the above,
3
3274
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 lists.Note that both these linked lists have same kind of data structure in their nodes.
10
42969
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 attribute values are part of markup or not.) Thanks.
16
2605
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
8654
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 arrays. Does anybody know if Mcilroys optimization is applicable to truly linked lists at all?
14
6138
by: phillipwei | last post by:
What's the best way to achieve this, or is this a bad idea?
48
2420
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
4022
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 rewritten as < (ie the less-than sign). Now I don't want this to happen, but something somewhere is...
0
9643
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
9480
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
10313
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
10147
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
10081
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
7494
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...
0
5378
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...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4044
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

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.