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. 4 1786
> 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
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 multidimensional 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
"Jim" <mr*****@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.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!
"Robert Kern" <ro*********@gmail.com> wrote in message
news:ma*************************************@pytho n.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 multidimensional 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! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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?
...
|
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...
|
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...
|
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...
|
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,...
|
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
|
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...
|
by: phillipwei |
last post by:
What's the best way to achieve this, or is this a bad idea?
|
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
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
|
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...
|
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,...
|
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: 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...
|
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...
| |