I am trying to reshape an array of shape (1, 400) to (20, 20) with numpy arrays and am struggling to find the proper syntax.
Consider the following:
import numpy as np
d_array = np.ones((1 + 10 * (20 + 1), 1 + 10 * (20 + 1)))
# tA and tB have shape (20,)
tA = np.array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1])
tB = np.array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1])
# X is a matrix of shape (5000, 400)
X = np.loadtxt(open("X.csv", "rb"), delimiter=",", skiprows=0)
Trying to assign and reshape at the same time doesn't seem to work with the way I'm doing it (below). I not sure of the proper syntax for this type of operation. Please help me understand what I'm doing wrong here.
Throws an error of: value array of shape(20,20) could not be broadcast to indexing result of shape(20,)
# save an array of first row from sample data of shape(1, 400)
xA = np.array([X[0, :]])
# try to assign both tA of shape(20,) and tB of shape(20,)
# a reshaped version of xA (20x20 = 400)
d_array [tA, tB] = np.reshape(xA, (20, 20))
I'm simply trying to create 20 reshaped arrays containing the 20 indices of each array (20x20)=400. I'm new to numpy, but am excited to learn more. Thanks for any help anyone can provide!