0

I want to generate an array called T with K points on this plot (in this case, K is 3). What I have so far is an array that has both x and y coordinates randomly generated in a certain range.

T = np.random.uniform(low=0.5, high=13.3, size=(K,N))

What I want, however, is to have the x coordinates be generated in a different range from the y coordinates such that the region populated by T is defined by (-15 < x < 0) and (-6 < y < 12). The context here is that T (shown in blue) is the initial centroids in K-means clustering and I want my initial centroids to start off close to my data which happens to lie in the (-15 < x < 0) and (-6 < y < 12) region.

Plot of my data shown in black along with initialized centroids

1 Answer 1

1

The function numpy.random.uniform can have different ranges :

import numpy as np 

N = 3
K = 2

T = np.random.uniform([-15,-6],[0,12],(N,K)).T
print(T)

>> [[-12.43132509  -4.86842272  -3.60063107]
    [1.88880676   4.14855554   6.34750037]]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.