📅  最后修改于: 2023-12-03 15:35:08.421000             🧑  作者: Mango
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.
To install Square Python NP, simply run the following command in your terminal:
pip install square_python_np
To use Square Python NP in your Python code, you can import it as follows:
import square_python_np as sp
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]]
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]]
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]]
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
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]]
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]]
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]]
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!