How do I remove the word 'array' from my prints when using numpy?

Hi all

My code is giving two errors when passing the tests

I believe these errors are due the appearance of the word ‘array’ in the results, as shown below:

How do I remove these instances of the word ‘array’ when using numpy?

Thanks for your time


P.S: I have found a bad solution, adding .tolist() to each line, is there a better solution?

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36

Challenge: Mean-Variance-Standard Deviation Calculator

Link to the challenge:

Are you returning the output or printing it?

1 Like

Hi @ilenia

Thanks for your quick response

This is how the code is run:

So I guess I’m returning and then printing, but I don’t see the difference, they both show the same thing right?

Running your code I get an OK, are you still having issues?

The reason why you get ‘ok’ is because I added .tolist() at the end of each line, as shown:

Is there a cleaner way to fix this?

That’s not a “word” that is the representation of the numpy-datatype and you cannot remove that other than changing the datatype - as you did with .tolist()

The reason you cannot change it, is because Python lists are a completly different type of object within the code and behaves entirely different. So the creators of Numpy made sure you can see their “array” is different from a Python list.
Hence you need to cast the Numpy array into a Python list. That’s the cleanest solution.

1 Like