Hi,
I am wondering how to replace column of one matrix with another matrix column. Here is my code.
TypeError: list indices must be integers or slices, not tuple"
I am wondering how to replace column of one matrix with another matrix column. Here is my code.
import random
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
# Matrix
A = [[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12]]
B = [[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]]
# Elements of Matrix
print("Matrix A =", A)
print("1nd row " + " A[0] = ", A[0])
print("2nd row " + " A[1] = ", A[1])
print("3rd row " + " A[2] = ", A[2])
print("3rd element of 2nd row " + " A[1][2] = ", A[1][2])
print("Last element of 1st Row" + " A[0][-1] = ", A[0][-1])
# Replacing Rows
B[0] = A[0]
print("Matrix A =", A)
print("Matrix B =", B)
# Replacing Cols
B[:,[0]] = A[:,[0]]
print("Matrix A =", A)
print("Matrix B =", B)I get this error " B[:,[0]] = A[:,[0]]TypeError: list indices must be integers or slices, not tuple"
