Reshape function & axis questions

Hello,

Might anyone be able to explain these in greater detail?

For instance, regarding axis, I tried the example with the region data and moved the axis to 0. This should concatenate the yield data as rows, yes? But instead there is an error. Why is this?

And regarding the reshape, I am confused exactly what is happening. If I change either the y or x value, an error occurs. What exactly is reshape doing? When I look it up in the codex, it more or less states that it is changing the shape of the matrix based on the x and y values input. But what are the rules in doing this? What makes a certain number set compatible with the data set? It is kind of confusing.

Thanks in advance if anyone is nice enough to tackle this with me.

Hello,

  1. When you change the axis to 0 , concatenate function tries to add the yield_data as rows but when you are trying to do row wise addition concatenate function works only when both the arrays have equal number of dimensions (or) columns.

  2. In the course we have seen that climate_data has a shape of (10000,3) and weights have a shape(3, ). Which means when we do matrix multiplicattion, we will get the shape of a resultant matrix as (10000, ) which is a 1D array. Now in order to concatenate both the arrays should be of same shape. So to convert 1D array to 2D array we use reshape(10000,1)

1 Like

#help

climate_results = np.concatenate((climate_data, yields.reshape(10000, 1)), axis=1)
print(climate_results)

array([[25. , 76. , 99. , 72.2, 72.2, 72.2],
[39. , 65. , 70. , 59.7, 59.7, 59.7],
[59. , 45. , 77. , 65.2, 65.2, 65.2],
…,
[99. , 62. , 58. , 71.1, 71.1, 71.1],
[70. , 71. , 91. , 80.7, 80.7, 80.7],
[92. , 39. , 76. , 73.4, 73.4, 73.4]])

Please describe your problem.