Syntax error using class numpy.ndarray

Hello
I need help. I am relatively new to python so my knowledge is hazy. I keep gettig the error below. I have tried to correct it based on what i know so far but all in vain. Kindly advise. Thank you.

Hi,

class classname {...}

is used to declare a new class. In this case, you should want to use np.ndarray to declare a new variable, so you probably should change your code to following:

a = np.ndarray(shape=(97, 97), dtype=float)

assume you have already import the numpy package.

Hello @Grace_Kansiime,

The assignment only requires you to write code for exercises, between the line ### START CODE HERE ### and the line ### END CODE HERE ###.

The line class numpy.ndarray(...) does not exist in the assignment. Why do you add that line?

Raymond

Thank you. I get a new error now .
TypeError: unsupported format string passed to numpy.ndarray.format

Hi
I was trying acouple of things I know and it showed as follows. I thought it would help. If you have great resources to help me in this. Kindly advise. Thank you.

So if I understand it correctly, you are adding the line for your own Python exericse and it has nothing to do with the assignment, am I right? If I am right, then we can continue the discussion without focusing on the assignment, and I would say I am happy to see that you are trying to learn numpy by do-it-yourself.

This is an official tutorial and if you go through it from start to end, and repeat the codes given therein, then you would have experienced a lot of useful basics of numpy. So, I would suggest you to do so. After that, if you want to do something outside of the tutorial, I would suggest you to have a clear goal first. Then you can create a simple input, and write down your expected output, and then pick the numpy function(s) to convert your input into output and see if the conversion is a successful one or not by comparing that output with your expected output.

Grace, for the line you added there, I suppose the goal behind is to initiate an array given the shape of (97, 97) and data type of float. This is a reasonable goal, and if you read the tutorial you will come across examples of how we can initialize an array given a shape. Please go through the tutorial.

Great try and keep trying!

Cheers,
Raymond

PS: Grace, since this post is about you practicing Python and numpy, I would suggest you to open a new topic next time under the “General discussion” category instead of putting it here in MLS C1 W2 because this is how we can better manage the posts. Thank you for your understanding. :slight_smile: