187k views
1 vote
Custom Matrix Creation Write a script that creates an n ×m (row ×col) matrix A that defines the values of each element by the following rules, where i represents the current row value and j represents the current column value: •If i j < 4 and i −j > 0, A(i, j) = ij •If i ×j < 4 and i + j > 5, A(i, j) = i −j •Otherwise, A(i, j) = 2i + 3j Display A. When publishing your script, use n = 6 and m = 4.

1 Answer

3 votes

Answer:

See Below

Step-by-step explanation:

Here's a Python script that creates an n x m matrix A based on the specified rules:

n = 6

m = 4

A = [[0 for j in range(m)] for i in range(n)]

for i in range(n):

for j in range(m):

if i*j < 4 and i+j > 5:

A[i][j] = i-j

elif i*j < 4 and i-j > 0:

A[i][j] = i*j

else:

A[i][j] = 2*i + 3*j

# Display matrix A

for row in A:

print(row)

This code initializes a matrix A of size n x m with all elements set to zero. It then iterates over each element in the matrix and applies the specified rules to assign a value to each element based on its row and column indices. Finally, it displays the resulting matrix A using a loop to print each row.

When running the script with n = 6 and m = 4, the output should look like:

[6, 9, 12, 15]

[4, 5, 6, -1]

[0, 0, 1, -2]

[0, 2, 4, 6]

[3, 5, 7, 9]

[6, 8, 10, 12]

User Alex Recarey
by
7.8k points