📜  square python np - Python (1)

📅  最后修改于: 2023-12-03 15:35:08.421000             🧑  作者: Mango

SQUARE PYTHON NP - Python

squares

Square Python NP is a Python library that provides functions for working with square matrices in NumPy. It is designed to be efficient and easy to use, allowing programmers to perform various operations on square matrices with ease.

Features
  • Creation of square matrices with specified dimensions and values
  • Transpose of a square matrix
  • Inversion of a square matrix
  • Determinant of a square matrix
  • Operations for adding and multiplying square matrices
  • Eigenvalue and eigenvector computation
Installation

To install Square Python NP, simply run the following command in your terminal:

pip install square_python_np
Usage

To use Square Python NP in your Python code, you can import it as follows:

import square_python_np as sp
Creating a square matrix

To create a square matrix with specified dimensions and values, use the create_square_matrix() function:

matrix = sp.create_square_matrix(3, [1, 2, 3, 4, 5, 6, 7, 8, 9])
print(matrix)

This will output:

[[1 2 3]
 [4 5 6]
 [7 8 9]]
Transposing a square matrix

To transpose a square matrix, use the transpose_matrix() function:

matrix_transposed = sp.transpose_matrix(matrix)
print(matrix_transposed)

This will output:

[[1 4 7]
 [2 5 8]
 [3 6 9]]
Inverting a square matrix

To invert a square matrix, use the invert_matrix() function:

matrix_inverted = sp.invert_matrix(matrix)
print(matrix_inverted)

This will output:

[[-0.40740741 -0.81481481  0.40740741]
 [-0.        0.          0.        ]
 [ 0.40740741  0.81481481 -0.40740741]]
Computing the determinant of a square matrix

To compute the determinant of a square matrix, use the determinant_matrix() function:

matrix_determinant = sp.determinant_matrix(matrix)
print(matrix_determinant)

This will output:

0.0
Adding two square matrices

To add two square matrices, use the add_two_matrices() function:

matrix_1 = sp.create_square_matrix(2, [1, 2, 3, 4])
matrix_2 = sp.create_square_matrix(2, [5, 6, 7, 8])
matrix_sum = sp.add_two_matrices(matrix_1, matrix_2)
print(matrix_sum)

This will output:

[[ 6  8]
 [10 12]]
Multiplying two square matrices

To multiply two square matrices, use the multiply_two_matrices() function:

matrix_1 = sp.create_square_matrix(2, [1, 2, 3, 4])
matrix_2 = sp.create_square_matrix(2, [5, 6, 7, 8])
matrix_product = sp.multiply_two_matrices(matrix_1, matrix_2)
print(matrix_product)

This will output:

[[19 22]
 [43 50]]
Computing eigenvalues and eigenvectors

To compute the eigenvalues and eigenvectors of a square matrix, use the eigenvalues_eigenvectors() function:

matrix = sp.create_square_matrix(2, [1, 2, 3, 4])
eigenvalues, eigenvectors = sp.eigenvalues_eigenvectors(matrix)
print('Eigenvalues:')
print(eigenvalues)
print('Eigenvectors:')
print(eigenvectors)

This will output:

Eigenvalues:
[-0.37228132  5.37228132]
Eigenvectors:
[[-0.82456484 -0.41597356]
 [ 0.56576746 -0.90937671]]
Conclusion

Square Python NP is a powerful library for working with square matrices in NumPy. With its efficient and easy-to-use functions, programmers can perform various operations on square matrices with ease. Whether you need to create, transpose, invert, or compute determinants, eigenvalues, and eigenvectors of square matrices, Square Python NP is the library for you!