np.cov() takes in a 1-d or 2-d matrix, so somehow we must “reshape” the 3-d input to 2-d. To solve this, I thought it would fitting to collapse the 1st dim(0 indexed, the axis that is n_images long) by getting its mean through examples.mean(axis = 1). This way, we maintain the features and their values at different gradient steps. But this seems to be an incorrect answer as I fail the unit test.
Taking guidance from the hint and using reshape to shape the examples to (examples.shape[0], examples.shape[-1]) and I get a ValuError: I cannot reshape an array with size 30720 to (60,4). Same with trying out the other dimensions.
So how do I go about this? Some pointers would be nice. Thank you
This was originally posted at the coursera forums.
ANSWER:
Maintain the final dimension of the examples matrix and somehow collapse the first two dimensions into one. This can be done with reshape by specifying the product of the sizes of the first two dimensions.
Foundations for reshaping array with the use of NumPy.
As it differs from situation to situation.
“We can reshape an 8 elements 1D array into 4 elements in 2 rows 2D array but we cannot reshape it into a 3 elements 3 rows 2D array as that would require 3x3 = 9 elements”.
Thus by specifying the product of the sizes of the first two row of an array and combining it as one variable , which is arr[x,y,z] =[{Y=(x*y)} *{z}] = ‘30720’ elements in your case. One can’t change the shape of an array to ‘2d’ as explained earlier.
Apart from this " There are several ways to resize the image like INTER_NEAREST, INTER_LINEAR , and more. There is no best way to select this parameter; it differs from situation to situation. This module is built on the NumPY library and has the resize () function, which can effectively resize images."
Notes: According to my knowledge, If you are looking for resizing the array you should simply compress the image pixel density itself and then try changing your size as per your system requirements.
@jamescasia, one handy feature to be aware of: reshape() lets you pass -1 for one of the dimensions and it will figure out the appropriate size for you. So, in this case, you could just pass -1 for the first parameter, rather than multiplying the size out yourself.