pyarma
PyArmadillo
linear algebra library for Python
[top] API Documentation for PyArmadillo 0.500


Preamble

  • This documentation assumes PyArmadillo was imported using
    from pyarma import *

  • If PyArmadillo was imported using "import pyarma as pa"
    then the pa. prefix must be added to each class and function;
    for example: pa.mat

  • See the syntax conversion table for differences between Matlab and PyArmadillo

  • First time users: please see the short example program

  • If you discover any bugs or regressions, please report them

  • History of API additions
 
  • Please cite the following article if you use PyArmadillo in your research and/or software.
    Citations are useful for the continued development and maintenance of the library.

    Jason Rumengan, Terry Yue Zhuo, Conrad Sanderson.
    PyArmadillo: a streamlined linear algebra library for Python.
    Journal of Open Source Software, Vol. 6, No. 66, 2021.

Overview
Matrix and Cube Classes
Member Functions & Variables
Generated Vectors/Matrices/Cubes
Functions of Vectors/Matrices/Cubes
Decompositions, Factorisations, Inverses and Equation Solvers (Dense Matrices)
Signal & Image Processing
Statistics & Clustering
Miscellaneous




Matrix and Cube Classes



mat, fmat, cx_mat, cx_fmat, umat, imat


cube, fcube, cx_cube, cx_fcube, ucube, icube


operators:  +    *  @  /  ==  !=  <=  >=  <  >  &&  ||




Member Functions & Variables



attributes


element/object access using []


element initialisation


.zeros()
 
.zeros( n_rows, n_cols )
.zeros( size(X) )


.ones()
.ones( n_rows, n_cols )
.ones( size(X) )


.eye()
.eye( n_rows, n_cols )
.eye( size(X) )


.randu()
.randu( n_rows, n_cols )
  (member function of matrix)
.randu( n_rows, n_cols, n_slice )
  (member function of cube)
.randu( size(X) )

.randn()
.randn( n_rows, n_cols )
  (member function of matrix)
.randn( size(X) )
  (member function of cube)


.fill( value )


.imbue( functor )
.imbue( lambda_function )


.clean( threshold )


.replace( old_value, new_value )


.transform( functor )
.transform( lambda_function )


.for_each( functor )
.for_each( lambda_function )


.set_size( n_rows, n_cols )
  (member function of matrix)
.set_size( n_rows, n_cols, n_slices )
  (member function of cube)
.set_size( size(X) )


.reshape( n_rows, n_cols )
  (member function of matrix)
.reshape( n_rows, n_cols, n_slices )
  (member function of cube)
.reshape( size(X) )


.resize( n_rows, n_cols )
  (member function of matrix)
.resize( size(X) )
  (member function of cube)


.copy_size( A )


.reset()


submatrix views


subcube views and slices


X[diag]
X[diag, k]


.set_imag( X )
.set_real( X )


.insert_rows( row_number, X )
.insert_rows( row_number, number_of_rows )
.insert_rows( row_number, number_of_rows, set_to_zero )
 
.insert_cols( col_number, X )
.insert_cols( col_number, number_of_cols )
.insert_cols( col_number, number_of_cols, set_to_zero )
 
.insert_slices( slice_number, X )
.insert_slices( slice_number, number_of_slices )
.insert_slices( slice_number, number_of_slices, set_to_zero )
  (member functions of cube)
 


.shed_row( row_number )
.shed_rows( first_row, last_row )
.shed_rows( vector_of_indices )
 
.shed_col( column_number )
.shed_cols( first_column, last_column )
.shed_cols( vector_of_indices )
 
.shed_slices( slice_number )
.shed_slices( first_slice, last_slice )
.shed_slices( vector_of_indices )
  (member functions of cube)


.swap_rows( row1, row2 )
.swap_cols( col1, col2 )


.swap( X )


iterators (dense matrices)


iterators (cubes)


iterators (dense submatrices & subcubes)


.as_col()
.as_row()


.t()
.st()


.i()


.min()
.max()


.index_min()
.index_max()


.eval()


.in_range( i )
.in_range( start : end )
 
.in_range( row, col )
  (member of mat)
.in_range( start_row : end_row, start_col : end_col )
  (member of mat)
 
.in_range( row, col , slice)
  (member of cube)
.in_range( start_row : end_row, start_col : end_col, start_slice: end_slice )
  (member of cube)
 
.in_range( first_row, first_col, size(X) )   (X is a matrix)
  (member of mat)
.in_range( first_row, first_col, size(n_rows, n_cols) )
  (member of mat)
 
.in_range( first_row, first_col, first_slice, size(Q) )   (Q is a cube)
  (member of cube)
.in_range( first_row, first_col, first_slice, size(n_rows, n_cols, n_slices) )
  (member of cube)


.is_empty()


.is_vec()
.is_colvec()
.is_rowvec()


.is_sorted()   (form 1)
.is_sorted( sort_direction )   (form 2)
.is_sorted( sort_direction, dim )   (form 3)


.is_trimatu()
.is_trimatl()


.is_diagmat()


.is_square()


.is_symmetric()
.is_symmetric( tol )


.is_hermitian()
.is_hermitian( tol )


.is_sympd()
.is_sympd( tol )


.is_zero()
.is_zero( tolerance )


.is_finite()


.has_inf()


.has_nan()


.print()
.print( header )


.brief_print()
.brief_print( header )


saving/loading matrices and cubes

.save( filename )
.save( filename, file_type )
       .load( filename )
.load( filename, file_type )

  • Caveat: for saving/loading HDF5 files, the hdf5.h header file and a suitable HDF5 library must be available at the time of PyArmadillo installation

  • Examples:

  • See also:





  • Generated Matrices



    linspace( start, end )
    linspace( start, end, N )


    logspace( A, B )
    logspace( A, B, N )


    regspace( start, end )
    regspace( start, delta, end )


    randperm( N )
    randperm( N, M )


    eye( n_rows, n_cols )
    eye( size(X) )


    ones( n_elem )
    ones( n_rows, n_cols )
    ones( n_rows, n_cols, n_slices )
    ones( size(X) )


    zeros( n_elem )
    zeros( n_rows, n_cols )
    zeros( n_rows, n_cols, n_slices )
    zeros( size(X) )


    randu( )
    randu( n_elem )
    randu( n_rows, n_cols )
    randu( n_rows, n_cols, n_slices )
    randu( size(X) )

    randn( )
    randn( n_elem )
    randn( n_rows, n_cols )
    randn( n_rows, n_cols, n_slices )
    randn( size(X) )


    randg( )
    randg( distr_param(a,b) )

    randg( n_elem )
    randg( n_elem, distr_param(a,b) )

    randg( n_rows, n_cols )
    randg( n_rows, n_cols, distr_param(a,b) )

    randg( n_rows, n_cols, n_slices )
    randg( n_rows, n_cols, n_slices, distr_param(a,b) )

    randg( size(X) )
    randg( size(X), distr_param(a,b) )


    randi( )
    randi( distr_param(a,b) )

    randi( n_elem )
    randi( n_elem, distr_param(a,b) )

    randi( n_rows, n_cols )
    randi( n_rows, n_cols, distr_param(a,b) )

    randi( n_rows, n_cols, n_slices )
    randi( n_rows, n_cols, n_slices, distr_param(a,b) )

    randi( size(X) )
    randi( size(X), distr_param(a,b) )


    toeplitz( A )
    toeplitz( A, B )
    circ_toeplitz( A )




    Functions of Matrices and Cubes



    abs( X )


    accu( X )


    affmul( A, B )


    all( X )   (form 1)
    all( X, dim )   (form 2)


    any( X )   (form 1)
    any( X, dim )   (form 2)


    approx_equal( A, B, method, tol )
    approx_equal( A, B, method, abs_tol, rel_tol )


    arg( X )


    as_scalar( expression )


    clamp( X, min_val, max_val )


    cond( A )


    conj( X )


    cross( A, B )


    cumsum( X )   (form 1)
    cumsum( X, dim )   (form 2)


    cumprod( X )   (form 1)
    cumprod( X, dim )   (form 2)


    det( A )


    diagmat( V )
    diagmat( V, k )

    diagmat( X )
    diagmat( X, k )


    diagvec( A )
    diagvec( A, k )


    diff( X )   (form 1)
    diff( X, k )   (form 2)
    diff( X, k, dim )   (form 3)



    dot( A, B )
    cdot( A, B )
    norm_dot( A, B )


    eps( X )


    B = expmat( A )
    expmat( B, A )


    B = expmat_sym( A )
    expmat_sym( B, A )


    find( X )
    find( X, k )
    find( X, k, s )


    find_finite( X )


    find_nonfinite( X )


    find_unique( X )
    find_unique( X, ascending_indices )


    fliplr( X )
    flipud( X )


    imag( X )
    real( X )


    ind2sub( size(X), index )   (form 1)
    ind2sub( size(X), vector_of_indices )   (form 2)


    index_min( M )
    index_min( M, dim )
    index_min( Q )
    index_min( Q, dim )
           index_max( M )
    index_max( M, dim )
    index_max( Q )
    index_max( Q, dim )
       
       
    (form 1)
    (form 2)


    inplace_trans( X )
    inplace_strans( X )


    C = intersect( A, B )   (form 1)
    intersect( C, iA, iB, A, B )   (form 2)


    join_rows( A, B )
    join_rows( A, B, C )
    join_rows( A, B, C, D )
     
    join_cols( A, B )
    join_cols( A, B, C )
    join_cols( A, B, C, D )
           join_horiz( A, B )
    join_horiz( A, B, C )
    join_horiz( A, B, C, D )
     
    join_vert( A, B )
    join_vert( A, B, C )
    join_vert( A, B, C, D )


    join_slices( cube C, cube D )
    join_slices( mat M, mat N )

    join_slices( mat M, cube C )
    join_slices( cube C, mat M )


    kron( A, B )


    result = log_det( A )   


    B = logmat( A )
    logmat( B, A )


    B = logmat_sympd( A )
    logmat_sympd( B, A )


    min( X )
    min( X, dim )
    min( A, B )
           max( X )
    max( X, dim )
    max( A, B )
       
       
       
    (form 1)
    (form 2)
    (form 3)



    nonzeros( X )


    norm( X )
    norm( X, p )


    normalise( X )   (form 1)
    normalise( X, p )   (form 2)
    normalise( X, p, dim )   (form 3)


    prod( X )   (form 1)
    prod( X, p )   (form 2)


    B = powmat( A, n )
    powmat( B, A, n )


    rank( X )
    rank( X, tolerance )


    rcond( A )


    repelem( A, num_copies_per_row, num_copies_per_col )


    repmat( A, num_copies_per_row, num_copies_per_col )


    reshape( X, n_rows, n_cols )    (X is a vector or matrix)
    reshape( X, size(Y) )

    reshape( Q, n_rows, n_cols, n_slices )    (Q is a cube)
    reshape( Q, size(R) )


    resize( X, n_rows, n_cols )    (X is a vector or matrix)
    resize( X, size(Y) )

    resize( Q, n_rows, n_cols, n_slices )    (Q is a cube)
    resize( Q, size(R) )


    reverse( X )   (form 1)
    reverse( X, p )   (form 2)


    R = roots( P )
    roots( R, P )


    shift( X, N )   (form 1)
    shift( X, N, dim )   (form 2)


    shuffle( X, )   (form 1)
    shuffle( X, dim )   (form 2)


    size( X )
    size( n_rows, n_cols )
    size( n_rows, n_cols, n_slices )


    sort( X )   (form 1)
    sort( X, sort_direction )   (form 2)
    sort( X, sort_direction, dim )   (form 3)


    sort_index( X )
    sort_index( X, sort_direction )

    stable_sort_index( X )
    stable_sort_index( X, sort_direction )


    B = sqrtmat( A )
    sqrtmat( B, A )


    B = sqrtmat_sympd( A )
    sqrtmat_sympd( B, A )


    sum( X )   (form 1)
    sum( X, dim )   (form 2)


    index = sub2ind( size(M), row, col )(M is a matrix)
    indices = sub2ind( size(M), matrix_of_subscripts )
        
    index = sub2ind( size(Q), row, col, slice)(Q is a cube)
    indices = sub2ind( size(M), matrix_of_subscripts )


    symmatu( A )
    symmatu( A, do_conj )

    symmatl( A )
    symmatl( A, do_conj )


    trace( X )


    trans( A )
    strans( A )


    trapz( X, Y )
    trapz( X, Y, dim )

    trapz( Y )
    trapz( Y, dim )


    trimatu( A )
    trimatu( A, k )

    trimatl( A )
    trimatl( A, k )


    trimatu_ind( size(A) )
    trimatu_ind( size(A), k )

    trimatl_ind( size(A) )
    trimatl_ind( size(A), k )


    unique( A )


    vectorise( X )
    vectorise( X, dim )
    vectorise( Q )


    miscellaneous element-wise functions:


    trigonometric element-wise functions (cos, sin, tan, ...)




    Decompositions, Factorisations, Inverses and Equation Solvers



    R = chol( X )
    R = chol( X, layout )

    chol( R, X )
    chol( R, X, layout )


    eigval, eigvec = eig_sym( X )

    eig_sym( eigval, X )

    eig_sym( eigval, eigvec, X )


    eigval, leigvec, reigvec = eig_gen( X )
    eigval, leigvec, reigvec = eig_gen( X, bal )

    eig_gen( eigval, X )
    eig_gen( eigval, X, bal )

    eig_gen( eigval, eigvec, X )
    eig_gen( eigval, eigvec, X, bal )

    eig_gen( eigval, leigvec, reigvec, X )
    eig_gen( eigval, leigvec, reigvec, X, bal )


    eigval, leigvec, reigvec = eig_pair( A, B )

    eig_pair( eigval, A, B )

    eig_pair( eigval, eigvec, A, B )

    eig_pair( eigval, leigvec, reigvec, A, B )


    U, H = hess( X )

    hess( H, X )

    hess( U, H, X )


    B = inv( A )
    inv( B, A )


    B = inv_sympd( A )
    inv_sympd( B, A )


    L, U, P = lu( X )
    lu( L, U, P, X )
    lu( L, U, X )


    B = null( A )
    B = null( A, tolerance )

    null( B, A )
    null( B, A, tolerance )


    B = orth( A )
    B = orth( A, tolerance )

    orth( B, A )
    orth( B, A, tolerance )


    B = pinv( A )
    B = pinv( A, tolerance )

    pinv( B, A )
    pinv( B, A, tolerance )


    Q, R = qr( X )   (form 1)
    qr( Q, R, X )   
     
    Q, R, P = qr( X, "vector" )   (form 2)
    qr( Q, R, P, X, "vector" )   
     
    Q, R, P = qr( X, "matrix" )   (form 3)
    qr( Q, R, P, X, "matrix" )   


    Q, R = qr_econ( X )
    qr_econ( Q, R, X )


    AA, BB, Q, Z = qz( A, B )
    AA, BB, Q, Z = qz( A, B, select )

    qz( AA, BB, Q, Z, A, B )
    qz( AA, BB, Q, Z, A, B, select )


    U, S = schur( X )

    schur( S, X )

    schur( U, S, X )


    X = solve( A, B )
    X = solve( A, B, settings )

    solve( X, A, B )
    solve( X, A, B, settings )


    mat U, mat s, mat V = svd( mat X )

    cx_mat U, mat s, cx_mat V = svd( cx_mat X )

    svd( mat s, X )

    svd( mat U, mat s, mat V, mat X )

    svd( cx_mat U, mat s, cx_mat V, cx_mat X )


    mat U, mat s, mat V = svd_econ( mat X )
    mat U, mat s, mat V = svd_econ( mat X, mode )

    cx_mat U, mat s, cx_mat V = svd_econ( cx_mat X )
    cx_mat U, mat s, cx_mat V = svd_econ( cx_mat X, mode )

    svd_econ( mat U, mat s, mat V, mat X )
    svd_econ( mat U, mat s, mat V, mat X, mode )

    svd_econ( cx_mat U, mat s, cx_mat V, cx_mat X )
    svd_econ( cx_mat U, mat s, cx_mat V, cx_mat X, mode )


    X = syl( A, B, C )
    syl( X, A, B, C )




    Signal & Image Processing



    conv( A, B )
    conv( A, B, shape )


    conv2( A, B )
    conv2( A, B, shape )


    cx_mat Y =  fft( X )
    cx_mat Y =  fft( X, n )

    cx_mat Z = ifft( cx_mat Y )
    cx_mat Z = ifft( cx_mat Y, n )


    cx_mat Y =  fft2( X )
    cx_mat Y =  fft2( X, n_rows, n_cols )

    cx_mat Z = ifft2( cx_mat Y )
    cx_mat Z = ifft2( cx_mat Y, n_rows, n_cols )


    interp1( X, Y, XI, YI )
    interp1( X, Y, XI, YI, method )
    interp1( X, Y, XI, YI, method, extrapolation_value )


    interp2( X, Y, Z, XI, YI, ZI )
    interp2( X, Y, Z, XI, YI, ZI, method )
    interp2( X, Y, Z, XI, YI, ZI, method, extrapolation_value )


    P = polyfit( X, Y, N )
    polyfit( P, X, Y, N )


    Y = polyval( P, X )




    Statistics & Clustering



    mean, median, stddev, var, spread


    cov( X, Y )
    cov( X, Y, norm_type )

    cov( X )
    cov( X, norm_type )


    cor( X, Y )
    cor( X, Y, norm_type )

    cor( X )
    cor( X, norm_type )


    hist( X )   (form 1a)
    hist( X, n_bins )   (form 1b)
    hist( X, centers )   (form 1c)
    hist( X, centers, dim )   (form 2)


    histc( X, edges )   (form 1)
    histc( X, edges, dim )   (form 2)


    quantile( X, P )   (form 1)
    quantile( X, P, dim )   (form 2)


    mat coeff, mat score, mat latent, mat tsquared = princomp( mat X )
    cx_mat coeff, cx_mat score, mat latent, cx_mat tsquared = princomp( cx_mat X )

    princomp( mat coeff, mat X )
    princomp( cx_mat coeff, cx_mat X )

    princomp( mat coeff, mat score, mat X )
    princomp( cx_mat coeff, cx_mat score, cx_mat X )

    princomp( mat coeff, mat score, vec latent, mat X )
    princomp( cx_mat coeff, cx_mat score, vec latent, cx_mat X )

    princomp( mat coeff, mat score, vec latent, vec tsquared, mat X )
    princomp( cx_mat coeff, cx_mat score, vec latent, cx_vec tsquared, cx_mat X )


    normpdf( X )
    normpdf( X, M, S )


    log_normpdf( X )
    log_normpdf( X, M, S )


    normcdf( X )
    normcdf( X, M, S )


    X = mvnrnd( M, C )
    X = mvnrnd( M, C, N )

    mvnrnd( X, M, C )
    mvnrnd( X, M, C, N )


    mat X = chi2rnd( DF )
    double s = chi2rnd( DF_scalar )
    mat v = chi2rnd( DF_scalar, n_elem )
    mat X = chi2rnd( DF_scalar, n_rows, n_cols )
    mat Y = chi2rnd( DF_scalar, size(X) )


    W = wishrnd( S, df )
    W = wishrnd( S, df, D )

    wishrnd( W, S, df )
    wishrnd( W, S, df, D )


    W = iwishrnd( T, df )
    W = iwishrnd( T, df, Dinv )

    iwishrnd( W, T, df )
    iwishrnd( W, T, df, Dinv )


    running_stat   (double-precision floating point)
    frunning_stat   (single-precision floating point)
    cx_running_stat   (complex double-precision floating point)
    cx_frunning_stat   (complex single-precision floating point)


    running_stat_vec   (double-precision floating point)
    frunning_stat_vec   (single-precision floating point)
    cx_running_stat_vec   (complex double-precision floating point)
    cx_frunning_stat_vec   (complex single-precision floating point)

    running_stat_vec(calc_cov)   (double-precision floating point)
    frunning_stat_vec(calc_cov)   (single-precision floating point)
    cx_running_stat_vec(calc_cov)   (complex double-precision floating point)
    cx_frunning_stat_vec(calc_cov)   (complex single-precision floating point)


    kmeans( means, data, k, seed_mode, n_iter, print_mode )




    Miscellaneous



    constants (pi, inf, speed of light, ...)


    wall_clock


    libraries



    Examples of Matlab/Octave syntax and conceptually corresponding PyArmadillo syntax




    example program



    History of API Additions, Changes and Deprecations


    sourceforge