Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mathgenerator/_gen_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
("DELETED", "DELETED"),
("basic_algebra", "algebra"),
("log", "algebra"),
("arrays_transpose", "algebra"),
("fraction_to_decimal", "basic_math"),
("decimal_to_binary", "computer_science"),
("binary_to_decimal", "computer_science"),
Expand Down
25 changes: 25 additions & 0 deletions mathgenerator/algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import math
import fractions
import sympy
import numpy as np


def basic_algebra(max_variable=10):
Expand Down Expand Up @@ -790,3 +791,27 @@ def orthogonal_projection(min_val=-10, max_val=10):
problem = f'Find the orthogonal projection of ${v}$ onto ${u}$'
solution = f'$[{y[0]}, {y[1]}]$'
return problem, solution



def arrays_transpose(max_dim=5, max_value=100):
r""" Transpose Arrays: In this case, 3-5 dimensional.
| Ex. Problem | Ex. Solution |
| --------- | ------------------- |
| What is the transpose of this 2-dimensional matrix: $\|[[73 61]
[50 69]] \|=$ | $[[73 50]
[61 69]]$ |
"""
a = random.randint(2, max_dim)
# Generate a random matrix dimension with NumPy (between 2 and 5) and random integers between 0 and 101 (inclusive).
original_array = np.random.randint(low=0, high=max_value, size=(a, a))

# Convert the original array to a string without '\n'
original_array_str = str(original_array).replace('\n', ',')

# Transpose original array without '\n'
transposed_array = str(original_array.transpose()).replace('\n', ',')

problem = f"What is the transpose of this {a}-dimensional array: {original_array_str}?"
solution = f"$The transpose is: {transposed_array}$"
return problem, solution