C3_W1_KMeans Assignment questions

Dear mentors/fellow learners,

I have been trying to replicate some of the commands from this assignment in IDLE, for practice so I can understand how they work better. I have run into a couple of issues and would be grateful if you could explain where I am going wrong:

i. Firstly, in the assignment, X is an m x n dimensional array (300 x 2).
The following command

print(“First five elements of X are:\n”, X[:5])

produces:

First five elements of X are:
[[1.84207953 4.6075716 ]
[5.65858312 4.79996405]
[6.35257892 3.2908545 ]
[2.90401653 4.61220411]
[3.23197916 4.93989405]]

My question is: what format is this array (X)? When I try to create a similar small array in IDLE, I get error messages, e.g.

C = [[1 2][3 4][5 6]]
SyntaxError: invalid syntax. Perhaps you forgot a comma?

If it is a numpy array, does it have to be, or is there an alternative way to create a matrix/array of X and Y coordinates without using numpy, i.e. just writing out in python?

ii. In a similar vein to (i), how can I write a single set of cartesian (X,Y) coordinates that I can then use with numpy norm method? I wanted to check my understanding of this norm method by using two simple X,Y coordinates, but
A = [3,4]
A = (3,4)
don’t work when use them (and a similar B) as arguments.

And is the value calculated equivalent to the Euclidean distance? The numpy documentation doesn’t mention this, and has a number of mathematical terms I’m not familiar with.

iii. For e.g. K = centroids.shape[0]

just to check the ‘0’ is a reference into the tuple created by the shape method, i.e. the first number (index 0) within the tuple?

Jem

Since X is an numpy array, you can use X.dtype() to display the data type.

To create a numpy array, you can use X = np.array(…), where you put the array values within the parenthesis.

You’ll need to “import numpy as np” also, within the IDLE session.