The need of np.array(cost)

Hi,

I can’t get the reason why do we need np.array(cost) in

YOUR CODE ENDS HERE

cost = np.squeeze(np.array(cost))

that is in the definition of the propagate function in the Logistic Regression with a Neural Network mindset programming assignment that is in the first week.

I tried without np.array and got all test passed.

Thanks

Hi @henrikh. I really do not know the answer. If one computes the cost in the propogate() function using ordinary NumPy functions (as I would), an ndarray of shape (1, 1) would result. The np.squeeze() part of the subsequent transformation would turn it into a scalar, which is fine (in fact it is required to pass the tests). But applying np.array() to something that is already an ndarray object should be moot. Alternatively, if one computes the cost using strictly native Python objects and manipulations, there may be a good reason to convert the cost to an ndarray. In any case, let’s not sweat it. :slight_smile:

Thank you! Yes, in the case of a general approach that the conversion no ndarray will be useful. I never thought about that.