<jupyter_start><jupyter_text>Matricies<jupyter_code>import numpy 
from numpy import *
from numpy.linalg import *<jupyter_output><empty_output><jupyter_text>With numpy matrices, you can add, subtract, multiply, find the transpose find the inverse, solve systems of linear equations and much more.Solve a system of consistent linear equations.  Refer to Lial Section 2.5 Example 7 Cryptography for the calculationRight hand side of system of equations has data entered as a list and converted to 3x1 matrix and then a 1x3 matrix using the transpose function. Similar steps are taken for the matrix A.<jupyter_code>rhs= [96, 87, 74]
rhs=matrix(rhs)
rhs=transpose(rhs)
print ('\nRight Hand Side of Equation')
print (rhs)

A =[[1, 3, 4], [2, 1, 3], [4, 2, 1]]
A= matrix(A)
print ('\nMatrix A')
print (A)<jupyter_output>Right Hand Side of Equation
[[96]
 [87]
 [74]]

Matrix A
[[1 3 4]
 [2 1 3]
 [4 2 1]]<jupyter_text>Numpy has various functions to perform matrix calculations.  The inverse function inv() is one of those.__Inverse of A__<jupyter_code>IA= inv(A)
IA<jupyter_output><empty_output><jupyter_text>In what follows, I am converting matrices with floating point numbers  to matrices with integer numbers.  This is optional and being done to show that it is possible to do so with numpy matrices.Note that the function dot() performs matrix multiplication. Verify inverse by multiplying matrix A and its inverse IA.__Identity Matrix__<jupyter_code>I= dot(IA,A)
I= int_(I)               # This converts floating point to integer.
I<jupyter_output><empty_output><jupyter_text>Solve the system of equations and convert to integer values. With numpy it is necessary to use dot() for the product.__Solution to Problem__<jupyter_code>result = dot(IA,rhs)
result = int_(result)    # This converts floating point to integer.
result<jupyter_output><empty_output><jupyter_text>__Illustration of solution with linalg.solve(,) function__<jupyter_code>result2= linalg.solve(A,rhs)
int_(result2)   # This converts floating point to integer.<jupyter_output><empty_output><jupyter_text>Some square matrices do not have inverses. The following example shows how this is handled with numpy.  Note the magnitude of the elements.__Example of an inverse matrix for inconsistent equations__<jupyter_code>A= [[1,2,3],[-3,-2,-1], [-1,0,1]]
A= array(A)
IA= inv(A)
IA<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08807416772018542, 'fraction_numerical': 0.020227560050568902, 'mean_word_length': 5.687323943661972, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '603626', 'license': 'MIT', 'n_tokens_mistral': 773, 'n_tokens_neox': 738, 'n_words': 290, 'path': 'Fall2019/MSDS400/pythonPractice/Module2/Matricies.ipynb', 'repo_name': 'kbridge14/regression_things', 'size': '2373'}