 |
Manipulations with sparse and dense matrix using UJMP
Source code name: "lalgebra_ujmp_matrix.py"
Programming language: Python
Topic: Linear Algebra/Matrices
DMelt Version 1.8. Last modified: 06/26/1971. License: Pro
https://datamelt.org/code/cache/lalgebra_ujmp_matrix_6913.py
To run this script using the DMelt IDE,
copy the above URL link to the menu [File]→[Read script from URL] of the DMelt IDE.
from org.ujmp.core import Matrix,DenseMatrix,SparseMatrix
# dense empty matrix with 4 rows and 4 columns
dense = DenseMatrix.Factory.zeros(4, 4)
# set entry at row 2 and column 3 to the value 5.0
dense.setAsDouble(5.0, 2, 3)
# set some other values
dense.setAsDouble(1.0, 0, 0)
dense.setAsDouble(3.0, 1, 1)
dense.setAsDouble(4.0, 2, 2)
dense.setAsDouble(-2.0, 3, 3)
dense.setAsDouble(-2.0, 1, 3)
print dense
# create a sparse empty matrix with 4 rows and 4 columns
sparse = SparseMatrix.Factory.zeros(4, 4)
sparse.setAsDouble(2.0, 0, 0)
# basic calculations
transpose = dense.transpose()
sum = dense.plus(sparse)
difference = dense.minus(sparse)
matrixProduct = dense.mtimes(sparse)
scaled = dense.times(2.0)
inverse = dense.inv()
pseudoInverse = dense.pinv()
determinant = dense.det()
singularValueDecomposition = dense.svd()
eigenValueDecomposition = dense.eig()
luDecomposition = dense.lu()
qrDecomposition = dense.qr()
choleskyDecomposition = dense.chol()
print choleskyDecomposition
choleskyDecomposition.showGUI()
You see the box below because you did not login.