| Home | Trees | Indices | Help |
|---|
|
|
| Classes | |
| LAValueError | |
| InvalidVectorException | |
| IncompatibleVectorException | |
| InvalidMatrixException | |
| IncompatibleMatrixException | |
| Functions | |||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
| Function Details |
Determine whether the given arg is a matrix, which must be a rectangular array of numbers, represented as a list/tuple of list/tuple elements, each of which is a vector of equal size. >>> is_matrix([]) True >>> is_matrix([[]]) True >>> is_matrix([1,2]) False >>> is_matrix([[1,2], (3,4)]) True >>> is_matrix([[1,2], [3,4,5]]) False >>> is_matrix([[1,2], ['0', 1]]) False >>> is_matrix([[.5, -1, 9], [4, 3, 19], [3, 6, 8], [0, 0, 1]]) True |
Calculates the dimensions of the given matrix, returning a pair consisting of the number of rows and the number of columns, raising an exception if any of the rows of the matrix have a different number of elements. >>> matrix_dimensions([]) (0, 0) >>> matrix_dimensions([[1,2,3]]) (1, 3) >>> matrix_dimensions([[1], [2], [3]]) (3, 1) >>> matrix_dimensions([[1, 2], [1, 2, 3]]) Traceback (most recent call last): ... InvalidMatrixException: Arg is not a matrix: [[1, 2], [1, 2, 3]]
|
Determine whether the given matrix is a square matrix, with the same number of rows and columns. >>> matrix_is_square([]) True >>> matrix_is_square([[]]) False >>> matrix_is_square([[1,1], [2,2], [3,3]]) False >>> matrix_is_square([[1,2,3], [4,5,6], [7,8,9]]) True >>> matrix_is_square([[1], [1,2]]) Traceback (most recent call last): ... InvalidMatrixException: Arg is not a matrix: [[1], [1, 2]]
|
Determine whether the given matrix is a diagonal matrix -- i.e., a square matrix with all nondiagonal entries equal to 0. >>> matrix_is_diagonal([]) True >>> matrix_is_diagonal([[0]]) True >>> matrix_is_diagonal([[0, 0], [0, 0], [0, 0]]) False >>> matrix_is_diagonal([[1, 0], [0, 2]]) True >>> matrix_is_diagonal([[1, 0], [1, 0]]) False
|
Determine whether the given matrix is a scalar matrix -- i.e., a diagonal matrix with all diagonal entries equal to each other. >>> matrix_is_scalar([]) True >>> matrix_is_scalar([[2]]) True >>> matrix_is_scalar([[3, 0], [0, 3]]) True >>> matrix_is_scalar([[3, 0], [1, 3]]) False
|
Determine whether the given matrix is an identity matrix -- i.e., a non-empty scalar matrix with all diagonal entries equal to 1. >>> matrix_is_identity([]) False >>> matrix_is_identity([[0]]) False >>> matrix_is_identity([[1]]) True >>> matrix_is_identity([[1, 1], [1, 1]]) False >>> matrix_is_identity([[1, 0], [0, 1]]) True >>> matrix_is_identity([[1, 0], [0, 1], [0, 0]]) False >>> matrix_is_identity([[2, 0], [0, 2]]) False
|
Determine whether the given matrix is symmetric -- i.e., whether it is equal to its own transpose. >>> matrix_is_symmetric([[1, 0], [0, 1]]) True >>> matrix_is_symmetric([[0, 1], [1, 0]]) True >>> matrix_is_symmetric([[1, 2], [2, 0]]) True >>> matrix_is_symmetric([[1, 2], [1, 2]]) False >>> matrix_is_symmetric([[1, 3, 2], [3, 5, 0], [2, 0, 4]]) True
|
Add the given matrices, which must have the same number of rows and columns. >>> matrix_plus([[1, 2], [3, 4]], [[4, 3], [2, 1]]) [[5, 5], [5, 5]] >>> matrix_plus([[1,2]], [[3, 4]]), matrix_plus([[1,2]], [[3, 4]])[0] == vector_plus([1,2], [3,4]) ([[4, 6]], True) >>> matrix_plus([[1]], [[1, 2]]) Traceback (most recent call last): ... IncompatibleMatrixException: Matrices must have same dimensions. Matrix 1 is 1 x 1, but matrix 2 is 1 x 2.
|
Subtract the second matrix from the first, both of which must have the same number of rows and columns. >>> matrix_minus([[3, 4], [1, 2]], [[1, 1], [1, 1]]) [[2, 3], [0, 1]] >>> matrix_minus([[1,2]], [[3, 4]]), matrix_minus([[1,2]], [[3, 4]])[0] == vector_minus([1,2], [3,4]) ([[-2, -2]], True) >>> matrix_minus([[1]], [[1, 2]]) Traceback (most recent call last): ... IncompatibleMatrixException: Matrices must have same dimensions. Matrix 1 is 1 x 1, but matrix 2 is 1 x 2.
|
Multiply the matrix A by the scalar s. >>> matrix_times(2, [[0,1], [1, 0]]) [[0, 2], [2, 0]] >>> matrix_times(-1, [[1,2,3,4]]) [[-1, -2, -3, -4]] >>> matrix_times(3, [[]]) [[]] >>> matrix_times(1, []) [] >>> matrix_times(3, [[1,2,3], [4,5,6], [7,8,9], [10, 11, 12]]) [[3, 6, 9], [12, 15, 18], [21, 24, 27], [30, 33, 36]]
|
Return the negative of the given matrix, or the matrix multiplied by scalar -1. >>> matrix_negative([]) [] >>> matrix_negative([[]]) [[]] >>> matrix_negative(((-1, 2), (2, -3))) [[1, -2], [-2, 3]]
|
Generate the transpose of the given m x n matrix, which is the n x m matrix with where each (i,j) element of the original matrix is the (j,i) element of the new matrix. >>> matrix_transpose([[1, 2], [3, 4], [5, 6]]) [[1, 3, 5], [2, 4, 6]] >>> matrix_transpose([]) [] >>> matrix_transpose([[]]) [] >>> matrix_transpose([[1,2,3], [4,5,6], [7,8,9]]) [[1, 4, 7], [2, 5, 8], [3, 6, 9]] >>> matrix_transpose(matrix_transpose([[1,2,3], [4,5,6], [7,8,9]])) [[1, 2, 3], [4, 5, 6], [7, 8, 9]] >>> matrix_transpose([[1,2,3]]) [[1], [2], [3]]
|
Calculate the product of matrices A and B, where A must have the same number of columns and B has rows. The result for A of size m x n and B of size n x r is an m x r matrix. >>> matrix_product([[1,1], [1,1]], [[1,1], [1,1]]) [[2, 2], [2, 2]] >>> matrix_product([], []) [] >>> matrix_product([[1, 3, -1], [-2, -1, 1]], [[-4, 0, 3, -1], [5, -2, -1, 1], [-1, 2, 0, 6]]) [[12, -8, 0, -4], [2, 4, -5, 7]]
|
Determine whether the two scalars are equal to accuracy of epsilon. >>> scalar_equal(0.9000000000000002, 0.9000000000000001) True >>> scalar_equal(1, 1) True >>> scalar_equal(1, 1.0) True >>> scalar_equal(1.0, 1.00000001) False |
Determine whether the two vectors are equal by determining if the pairwise components are equal to accuracy of epsilon. >>> vector_equal([2], [2]) True >>> vector_equal([1.0, 0.9000000000000002], [1, 0.9000000000000001]) True
|
Determine whether the two matrices are equal by determining if the corresponding components are equal to accuracy of epsilon. >>> matrix_equal([], []) True >>> matrix_equal([[1, 2, 3], [3.9000000000000001, 2, 1]], [[1, 2, 3], [3.9, 2, 1]]) True
|
Create a zero vector with same size as the given vector, or having as many elements as the given int. >>> vector_zero(3) [0, 0, 0] >>> vector_zero([1,2,3,4]) [0, 0, 0, 0] >>> vector_zero([]) [] |
Create a unit-length vector in direction of v. >>> vector_unit_length([3,3]) [0.70710678118654757, 0.70710678118654757]
|
Multiplies the vector by the given scalar. >>> vector_times(3, [1,2]) [3, 6] >>> vector_times(5, [4,-2,7]) [20, -10, 35] >>> vector_times(0, [1,2,3]) [0, 0, 0]
|
Calculate the vector resulting from the addition of the two given vectors. >>> vector_plus([1,2], [3,4]) [4, 6] >>> vector_plus([0.5, 1], [2.5, -1]) [3.0, 0]
|
Subtract the second vector from the first vector. >>> vector_minus([2], [-3]) [5] >>> vector_minus([1,2,3], [2,3,4]) [-1, -1, -1]
|
Calculate the dot product of the given vectors, which is defined as the sum of the pairwise products of the vectors. >>> vector_product([0,0], [0,1]) 0 >>> vector_product([1,2,-3], [-3,5,2]) 1
|
Calculate the length, or norm, of the vector, which is defined to be the square root of the sum of the squares of the components of the vector. >>> vector_norm([0,1]) 1.0 >>> vector_norm([1,1]), scalar_equal(vector_norm([1,1]), sqrt(2)) (1.4142135623730951, True) >>> vector_norm([2,-1,3]), scalar_equal(vector_norm([2,-1,3]), sqrt(14)) (3.7416573867739413, True) >>> vector_norm([sqrt(2), -1, 1]) 2.0
|
Calculate the distance between the two vectors, which is defined to be the norm of the difference between the vectors. >>> vector_distance([sqrt(2), 1, -1], [0, 2, -2]) 2.0 >>> vector_distance([0,1], [1,0]) 1.4142135623730951 >>> vector_distance([-1,2], [3,1]) 4.1231056256176606
|
Determine whether the two vectors are orthogonal, which is defined by whether the dot product is 0. >>> vector_is_orthogonal([0,1], [1,0]) True >>> vector_is_orthogonal([2,-1,1], [1,-2,-1]) False >>> vector_is_orthogonal([1,1,-2], [3,1,2]) True
|
Determine the angle between the two vectors, in radians. >>> vector_angle([0,1,1], [1,0,1]), scalar_equal(vector_angle([0,1,1], [1,0,1]), pi/3) (1.0471975511965979, True) >>> vector_angle([0.9, 2.1, 1.2], [-4.5, 2.6, -0.8]) 1.5376292299388497
|
Calculate the projection of v onto u. >>> vector_project([2,1], [-1, 3]), vector_equal(vector_project([2,1], [-1, 3]), [2.0/5, 1.0/5]) ([0.40000000000000002, 0.20000000000000001], True) >>> vector_project([0,0,1], [1,2,3]), vector_equal(vector_project( [0,0,1], [1,2,3]), [0,0,3]) ([0.0, 0.0, 3.0], True)
|
Determine whether the arg is a vector, or a list or tuple of numbers. >>> is_vector('') False >>> is_vector([]) True >>> is_vector(()) True >>> is_vector((1,)) True >>> is_vector([1]) True >>> is_vector([1,2,3,4]) True >>> is_vector((1,2,3)) True >>> is_vector([1, 0.5, -9L]) True >>> is_vector([1, 2, "3"]) False >>> is_vector([[0]]) False >>> is_vector([[1,2]]) False |
Determine whether s is a scalar, which is either a float, int, or long. The integral values 0 and 1 may also be given as False and True, respectively. >>> is_scalar(0) True >>> is_scalar(True) True >>> is_scalar(-9.2) True >>> is_scalar(100L) True >>> is_scalar((1,2)) False |
| Home | Trees | Indices | Help |
|---|
| Generated by Epydoc 3.0.1 on Sun Mar 1 20:23:43 2009 | http://epydoc.sourceforge.net |