[prev in list] [next in list] [prev in thread] [next in thread]
List: python-ideas
Subject: [Python-ideas] Re: A bit change to create a matrix variable in Python as easy as MATLAB and Julia!
From: Todd <toddrjen () gmail ! com>
Date: 2019-11-09 22:48:46
Message-ID: CAFpSVpKsJPAppimTr==gNfcx8NUMBEQ6L-Q-r8Co5BJVGNt=BQ () mail ! gmail ! com
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
I am pretty sure this is a backwards incompatible change. It isn't likely
syntax, but I think it is possible.
I also don't like having to wait until the end of the expression to find
out it isn't a list. And also seems like it would be easy to miss in a
non-trivial case.
How would you be parsed?
a = [1, 2, 3;
4, 5, 6]
On Fri, Nov 8, 2019, 09:13 <yejustme@163.com> wrote:
> In recent years, python has become very popular due to the rise of data
> science and machine learning. This is mainly because Python is easy to
> learn and has a large number of third-party libraries, thus accumulating a
> large number of users.
> When Python is applied to scientific computing, there are two
> problems. One is that Python itself is not fast enough, and the other is
> that matrix is not a basic data type. The first problem can be well solved
> by rewriting key codes in C/C++, or by using numba. For the second one,
> people have invented Numpy which has become the actual matrix computing
> standard in Python. Although it can do linear algebra, limited by the
> syntax of Python, using Numpy to initialize a matrix is always not simple
> enough. We have to do it like this:
> import numpy as np
> a=np.array([1,2,3])
> b=np.array([[1,2,3],[4,5,6]])
> While, you know, in Matlab and Julia(A new ambitious and interesting
> language) it is in this way:
> a=[1,2,3] or a=[1 2 3]
> b=[1,2,3;4,5,6] or b=[1 2 3;4 5 6]
>
> Of course, python, as a general-purpose language, is not limited to
> scientific computing, but also used for crawlers, web development, and even
> writing GUI programs. Therefore, many developers do not need matrix
> operations, nor need to use numpy as a standard library.
> Since numpy has become the cornerstone of Python scientific
> computing, there is no need to reinvent another wheel, that is, to design
> new matrix data types. I suggest adding some parsing rules to the List data
> type to facilitate the initialization of a matrix.
>
> (1) Keeping the original syntax of List unchanged,for example:
> a = [1,2,3] # will be parsed to a normal list.
> b = [[1,2,3],[4,5,6]] # will be parsed to a normal list,too.
> Simply put, all the original list syntax remains unchanged.
> (2) Using semicolons as a flag to make a better integration of a List-like
> data type and Numpy. The Python interpreter will check whether the numpy
> library is installed. If not, it will stop running and remind the user to
> install it. The expected syntax:
> c = [1,2,3;] or c = [1 2 3;] or c = [1 2 3]
> Notice the semicolon after the last number. If numpy is found, c
> will be parsed as a Numpy ndarray. All these forms are equivelent to c =
> np.array([1,2,3]). For a vector, the semicolon is the key for Python to
> parse it as a Numpy ndarray.
>
> d=[1,2,3;4,5,6] or d=[1,2,3;4,5,6;] or d=[1 2 3;4 5 6] or d=[1 2
> 3;4 5 6;]
> Notice the semicolons. If numpy is found, d will be parsed as a
> Numpy ndarray. All these forms are equivelent to
> d=np.array([[1,2,3],[4,5,6]])
> You see,for defining a matrix or a vector,it will be nearly as
> simple as Matalab or Julia!
> Thank you!
> _______________________________________________
> Python-ideas mailing list -- python-ideas@python.org
> To unsubscribe send an email to python-ideas-leave@python.org
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at
> https://mail.python.org/archives/list/python-ideas@python.org/message/MGMU6TMPBP7HKIA2TAQI4QG4KCSEQVVQ/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
[Attachment #5 (text/html)]
<div dir="auto"><div><div dir="auto">I am pretty sure this is a backwards \
incompatible change. It isn't likely syntax, but I think it is \
possible.</div><div dir="auto"><br></div><div dir="auto">I also don't like having \
to wait until the end of the expression to find out it isn't a list. And also \
seems like it would be easy to miss in a non-trivial case. </div><div \
dir="auto"><br></div>How would you be parsed?<div dir="auto"><br></div><div \
dir="auto">a = [1, 2, 3;</div><div dir="auto"> 4, 5, 6]</div><br><br><div \
class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Nov 8, 2019, 09:13 \
<<a href="mailto:yejustme@163.com" rel="noreferrer noreferrer" \
target="_blank">yejustme@163.com</a>> wrote:<br></div><blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex">In recent years, python has become very popular due to the \
rise of data science and machine learning. This is mainly because Python is easy to \
learn and has a large number of third-party libraries, thus accumulating a large \
number of users. <br> When Python is applied to scientific computing, there are two \
problems. One is that Python itself is not fast enough, and the other is that matrix \
is not a basic data type. The first problem can be well solved by rewriting key codes \
in C/C++, or by using numba. For the second one, people have invented Numpy which has \
become the actual matrix computing standard in Python. Although it can do linear \
algebra, limited by the syntax of Python, using Numpy to initialize a matrix is \
always not simple enough. We have to do it like this:<br> import numpy as np<br>
a=np.array([1,2,3])<br>
b=np.array([[1,2,3],[4,5,6]])<br>
While, you know, in Matlab and Julia(A new ambitious and interesting \
language) it is in this way:<br> a=[1,2,3] or a=[1 2 3]<br>
b=[1,2,3;4,5,6] or b=[1 2 3;4 5 6]<br>
<br>
Of course, python, as a general-purpose language, is not limited to \
scientific computing, but also used for crawlers, web development, and even writing \
GUI programs. Therefore, many developers do not need matrix operations, nor need to \
use numpy as a standard library.<br> Since numpy has become the cornerstone of \
Python scientific computing, there is no need to reinvent another wheel, that is, to \
design new matrix data types. I suggest adding some parsing rules to the List data \
type to facilitate the initialization of a matrix. <br> <br>
(1) Keeping the original syntax of List unchanged,for example:<br>
a = [1,2,3] # will be parsed to a normal list.<br>
b = [[1,2,3],[4,5,6]] # will be parsed to a normal list,too.<br>
Simply put, all the original list syntax remains unchanged.<br>
(2) Using semicolons as a flag to make a better integration of a List-like data type \
and Numpy. The Python interpreter will check whether the numpy library is installed. \
If not, it will stop running and remind the user to install it. The expected \
syntax:<br> c = [1,2,3;] or c = [1 2 3;] or c = [1 2 3] <br>
Notice the semicolon after the last number. If numpy is found, c will be \
parsed as a Numpy ndarray. All these forms are equivelent to c = np.array([1,2,3]). \
For a vector, the semicolon is the key for Python to parse it as a Numpy ndarray.<br> \
<br>
d=[1,2,3;4,5,6] or d=[1,2,3;4,5,6;] or d=[1 2 3;4 5 6] or d=[1 2 3;4 5 6;] \
<br>
Notice the semicolons. If numpy is found, d will be parsed as a Numpy \
ndarray. All these forms are equivelent to \
d=np.array([[1,2,3],[4,5,6]])<br>
You see,for defining a matrix or a vector,it will be nearly as simple \
as Matalab or Julia!<br> Thank you!<br>
_______________________________________________<br>
Python-ideas mailing list -- <a href="mailto:python-ideas@python.org" rel="noreferrer \
noreferrer noreferrer" target="_blank">python-ideas@python.org</a><br> To unsubscribe \
send an email to <a href="mailto:python-ideas-leave@python.org" rel="noreferrer \
noreferrer noreferrer" target="_blank">python-ideas-leave@python.org</a><br> <a \
href="https://mail.python.org/mailman3/lists/python-ideas.python.org/" \
rel="noreferrer noreferrer noreferrer noreferrer" \
target="_blank">https://mail.python.org/mailman3/lists/python-ideas.python.org/</a><br>
Message archived at <a \
href="https://mail.python.org/archives/list/python-ideas@python.org/message/MGMU6TMPBP7HKIA2TAQI4QG4KCSEQVVQ/" \
rel="noreferrer noreferrer noreferrer noreferrer" \
target="_blank">https://mail.python.org/archives/list/python-ideas@python.org/message/MGMU6TMPBP7HKIA2TAQI4QG4KCSEQVVQ/</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer \
noreferrer noreferrer noreferrer" \
target="_blank">http://python.org/psf/codeofconduct/</a><br> </blockquote></div>
</div></div>
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-leave@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/DB65OI7MC6YHY7QBJ2A4VSBDR2VMBDPT/
Code of Conduct: http://python.org/psf/codeofconduct/
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic