Nathaniel,

This is not a comment on any present matrix support, but deals with the matrix class, which existed back when Todd Miller of the Space Telescope Group supported numpy.

Matrix is a sub-class of ndarray.

I'm suggesting that anything which is produced by this class should be checked for the Characteristics of a Matrix.    These characteristics include:
  1. a rectangular array; and
  2. all numeric values.
Others might suggest other characteristics.

I suggest that any matrix which is returned should check the characteristics and reject any incompatible cases.

An example of a failure was given:
A1= np.matrix([[1, 2, -2], [-3, -1, 4], [4, 2 -6]])
A comma was missing
Subsequent statements might have been shown:
print('A1=', A1)
print ('Identity: A1 * A1.I: ', A1 * A1.I)  ##  Grief here numpy
# Reported in a misleading way:
                                                # Traceback (most recent call last):
                                                #  File "<string>", line 254, in run_nodebug
                                                #  File "C:\Users\cjw_2\Documents           \stephanie.py", line 31, in <module>
                                                #    print ('Identity: A1 * A1.I: ', A1 * A1.I)  ##  Grief here numpy
                                                # File "C:\Python27\lib\site-packages\numpy\matrixlib\defmatrix.py", line 870, in getI
                                                #   return asmatrix(func(self))
                                                #  File "C:\Python27\lib\site-packages\numpy\linalg\linalg.py", line 1584, in pinv
                                                #   a = a.conjugate()
                                                # AttributeError: 'list' object has no attribute 'conjugate'
                                                # >>>
A check up front would have been more helpful, especially for a user who is not familiar with Numpy.

I hope that this is clearer.

Colin W.



On 05-Jan-15 1:58 PM, Nathaniel Smith wrote:
I'm afraid that I really don't understand what you're trying to say. Is
there something that you think numpy should be doing differently?

On Mon, Jan 5, 2015 at 6:40 PM, Colin J. Williams <cjwilliams43@gmail.com>
wrote:

One of the essential characteristics of a matrix is that it be rectangular.

This is neither spelt out or checked currently.

The Doc description refers to a class:

   - *class *numpy.matrix[source]
   <http://github.com/numpy/numpy/blob/v1.9.1/numpy/matrixlib/defmatrix.py#L206>

Returns a matrix from an array-like object, or from a string of data. A
matrix is a                specialized 2-D array that retains its 2-D
nature through operations. It has certain special operators, such as *
(matrix multiplication) and ** (matrix power).

This illustrates a failure, which is reported later in the calculation:

A2= np.matrix([[1, 2, -2], [-3, -1, 4], [4, 2 -6]])

Here 2 - 6 is treated as an expression.

Wikipedia offers:

In mathematics <http://en.wikipedia.org/wiki/Mathematics>, a *matrix*
(plural *matrices*) is a rectangular
<http://en.wikipedia.org/wiki/Rectangle> *array
<http://en.wiktionary.org/wiki/array>*[1]
<http://en.wikipedia.org/wiki/Matrix_%28mathematics%29#cite_note-1> of
numbers <http://en.wikipedia.org/wiki/Number>, symbols
<http://en.wikipedia.org/wiki/Symbol_%28formal%29>, or expressions
<http://en.wikipedia.org/wiki/Expression_%28mathematics%29>, arranged in *rows
<http://en.wiktionary.org/wiki/row>* and *columns
<http://en.wiktionary.org/wiki/column>*.[2]
<http://en.wikipedia.org/wiki/Matrix_%28mathematics%29#cite_note-2>[3]
<http://en.wikipedia.org/wiki/Matrix_%28mathematics%29#cite_note-3> The
individual items in a matrix are called its *elements* or *entries*. An
example of a matrix with 2 rows and 3 columns is
[image: \begin{bmatrix}1 & 9 & -13 \\20 & 5 & -6 \end{bmatrix}.]In the
Numpy context, the symbols or expressions need to be evaluable.

Colin W.





_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion