473,395 Members | 1,647 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,395 software developers and data experts.

Any way to program custom syntax to python prompt? >> I want to editmatrices.

Python matrices are usually defined with numpy scipy array or similar.
e.g.
>>matrix1 = [[1, 2], [3, 4], [5, 6]]
I would like to have easier way of defining matrices,
for example:
>>matrix = [1, 2; 3, 4; 5, 6]
>>matrix =
[ 1, 2;
3, 4;
5, 6;]

Any ideas how could this be done? The ";" sign is reserved, the "[ ]"
is used for lists.

Also, how to program custom operations for this new "class?"
matrix ???

For example:
>>matrix + 2
[ 3, 4;
5, 6;
7, 8;]

Possibly with operator overloading?
I appreciate all your comments, directions, pointers.
mosi
Dec 11 '07 #1
3 1420
On 11 Des, 01:54, mosi <skawan...@gmail.comwrote:
Python matrices are usually defined with numpy scipy array or similar.
e.g.>>matrix1 = [[1, 2], [3, 4], [5, 6]]
That is a list of Python lists, not a NumPy array or matrix.

For example:>>matrix + 2

[ 3, 4;
5, 6;
7, 8;]

Possibly with operator overloading?
Go and get NumPy: www.scipy.org

Then buy Travis Oliphant's book.


Dec 11 '07 #2
On Mon, 10 Dec 2007 16:54:08 -0800, mosi wrote:
Python matrices are usually defined with numpy scipy array or similar.
e.g.
>>>matrix1 = [[1, 2], [3, 4], [5, 6]]
I would like to have easier way of defining matrices, for example:
>>>matrix = [1, 2; 3, 4; 5, 6]
>>>matrix =
[ 1, 2;
3, 4;
5, 6;]

Any ideas how could this be done? The ";" sign is reserved, the "[ ]" is
used for lists.
You could have some class `Matrix` with a constructor taking a string, as
in ``Matrix("[1, 2; 3, 4; 5, 6]")``. A very naive parser could just strip
trailing/leading brackets and all spaces, split on ';', split again on
',', done.
Also, how to program custom operations for this new "class?" matrix ???

For example:
>>>matrix + 2
[ 3, 4;
5, 6;
7, 8;]

Possibly with operator overloading?
Yes, by simply overloading __add__ et al. See http://docs.python.org/ref/
specialnames.html for details (certainly, "Emulating numeric types"
should be interesting to you).
I appreciate all your comments, directions, pointers. mosi
Cheers,
Dec 11 '07 #3
On 11 Dec 2007 04:14:09 GMT, Stargaming <st********@gmail.comwrote:
On Mon, 10 Dec 2007 16:54:08 -0800, mosi wrote:
Python matrices are usually defined with numpy scipy array or similar.
e.g.
>>matrix1 = [[1, 2], [3, 4], [5, 6]]
I would like to have easier way of defining matrices, for example:
>>matrix = [1, 2; 3, 4; 5, 6]
>>matrix =
[ 1, 2;
3, 4;
5, 6;]

Any ideas how could this be done? The ";" sign is reserved, the "[ ]" is
used for lists.
I think mosi was looking to dynamically modify the syntax of Python
itself, as opposed to working around the existing syntax. This
includes things like messing with reserved symbols and keywords.

The interpreter is compiled with these definitions built in, so to
change them would conceivably require a recompile. If this is the
case, then mosi may be out of luck. Then again, people have done some
interesting dynamic modifications to the interpreter during runtime
without recompiling. Psyco is the best example of this that comes to
mind. Maybe someone more versed in Psyco-esque interpreter voodoo
would be able to help.

--
nasser
Dec 11 '07 #4

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

Similar topics

2
by: Rene Pijlman | last post by:
I can't seem to find any way to specify the character encoding with the DB API implementation of PyPgSQL. There is no mention of encoding and Unicode in the DB API v2.0 spec and the PyPgSQL README....
1
by: Michael R Seefelt | last post by:
I have written a simple C-program that loads a Python Function that connects to a PostgreSQL database> When I only load and execute the Python function all works OK. If I call the Python function a...
5
by: john | last post by:
Hi I am devlopeing a data centric intranetsite with data in mysql database I would like your opinion on this architecture Data will be fetched from database by python & converted into xml The...
5
by: Ernesto | last post by:
Is there a way to compile a C program into a .pyc file that has the same behavior as the compiled C program? Thanks!
4
by: news | last post by:
I've just started to test/learn python. I've got Linux > mandrake9 > python & documentation. What I'll initially want to be doing needs file I/O, so I wanted to confirm file I/O early in my...
5
bartonc
by: bartonc | last post by:
Two new sub forums have been added to the Python Forum. These are NOT Q&A forums, but threads will be open to discussion. In Python > Python Code you will find snippets submitted by experts and...
15
by: rh0dium | last post by:
Hi Folks, OK I love the logging module. I use it everywhere. I was happily putting at the top of each of my scripts ------<snip>------ #!/usr/bin/env python2.4 import logging
4
by: coaxfiber | last post by:
Hi guys, my problem is when I installing the Apache v2.2.4 as my local server to run my php, and then run the test configuration, it tells me this error: httpd.exe: Syntax error on line 152 of...
4
by: pdlemper | last post by:
Have carefully installed Python 2.5.1 under XP in dir E:\python25 . ran set path = %path% ; E:\python25 Python interactive mode works fine for simple arithmetic . Then tried >> import math Get...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
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...
0
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...
0
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...

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.