Why reshaping arrays that already have only one column?

Why do we need to reshape arrays in the following exercise? If we look at the starbucks_customers.csv dataset, isn’t distance a one-column array already before reshaping?

https://www.codecademy.com/paths/machine-learning-fundamentals/tracks/mle-fe-data-transformations/modules/fe-data-transformations-for-feature-analysis/lessons/fe-numerical-transformations/exercises/fe-min-max-normalization-part-2

It’s not really about reshaping an array into one column as such.

It’s my understanding that with min/max normalization you want to find the min and max values and then set each to 0 and 1 (respectively). Then the rest of the data points will fall between 0 and 1, depending on the distance between those two values of 0 & 1. Basically, you’re trying to get everything on the same scale.

Thank you very much for your reaction. I do understand the basic idea of min-max normalization. But there must be something I am missing.

Reshaping is done in both the standardization with sklearn task:

reshaped_distance = np.array(distance).reshape(-1,1

and the min-max normalization with sklearn:

#reshape our array to prepare it for the mmscaler
reshaped_distance = np.array(dis).reshape(-1,1)

In both cases, a single column is extracted from the starbucks_customers.csv and set into a variable before reshaping. My question is: if we already have one single column, why do we need to reshape?

You’re close.

My code:

spent_reshaped =np.array(spent).reshape(-1,1)

mmscaler = MinMaxScaler()

reshaped_scaled = mmscaler.fit_transform(spent_reshaped)

print(np.min(reshaped_scaled))
print(np.max(reshaped_scaled))

So, first you have to reshape the array (column) to prepare it for the mmscaler and THEN you apply mmscaler.fit_transform(reshaped_data) to the reshaped data.

The replies here don’t answer your question - did you ever get clarification on this? I am wondering the same thing!

No, it is not completely clear to me yet! Let me know if you figure it out!

The reshape() function is used to give a new shape to an array without changing its data . Array to be reshaped. The new shape should be compatible with the original shape. If an integer, then the result will be a 1-D array of that length.