MapdlMath.matrix(matrix, name=None, triu=False)

Send a scipy matrix or numpy array to MAPDL.

  • matrix (np.ndarray) – Numpy array to send as a matrix to MAPDL.

  • name (str, optional) – APDLMath matrix name. Optional and defaults to a random name.

  • triu (bool, optional) – True when the matrix is upper triangular, False when unsymmetric.


ans_mat (MapdlMath.AnsMat) – MapdlMath matrix.


Generate a random sparse matrix

>>> from scipy import sparse
>>> sz = 5000
>>> mat = sparse.random(sz, sz, density=0.05, format='csr')
>>> ans_mat = mm.matrix(mat, name)
>>> ans_mat
APDLMath Matrix 5000 x 5000

Read the matrix back to Python

>>> ans_mat.asarray()
<500x5000 sparse matrix of type '<class 'numpy.float64'>'
        with 1250000 stored elements in Compressed Sparse Row format>