On Thu, Nov 7, 2019, at 22:19, yejus...@163.com wrote:
> (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!

Possible alternate mechanisms:

Make any such expression implicitly call a special function named e.g. 
__matrixhook__
- called by name, so a default in builtins and one could be set locally in a 
module or imported from numpy
- or have the special function be installable in sys.matrixhook rather than 
based on a lexically scoped special name

The default hook could:
- raise an error suggesting to install numpy as in OP's suggestion
- just build a list of lists

These would require slightly more boilerplate (from numpy import 
__matrixhook__, or perhaps numpy could automatically initialize sys.matrixhook 
when loaded), but wouldn't favor a single non-stdlib library.
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@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/VEWHLESVE4M7EYW7REKW6FT5NEGLQRPI/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to