0

Im working in an assigment that ask me to create a d-dimensional variable x that is uniformely distributed on the unit sphere such that its norm equals 1 (x_n c R^d, ||x_n||_2 = 1). I know how to create multivariate uniform variables, however I'm unable to recreate the added constrain.

Right now I have the following

import numpy as np
trainN = 200
testN = 50
d = 5

xTest = np.random.random((testN, d))
xTrain = np.random.random((testN, d))
for i in xTrain:
    print(np.linalg.norm(i))

However, this doesnt seem like the proper aproach to me, as x is not restricted to [0,1], and the norms vary wildly between entrances.

Could someone lend me a hand?

PabloM
  • 1
  • 1
  • Hi and welcome to SO. Please show what you have tried so far, thanks. – Jacques Gaudin May 09 '22 at 10:59
  • @JacquesGaudin Thank you for the welcome! I have uploaded my code, though I dont know how much help it can provide, as I think its wrong – PabloM May 09 '22 at 12:05
  • 1
    This answer might help you. Have a look at the comments too! https://stackoverflow.com/a/33977530/1388292 – Jacques Gaudin May 09 '22 at 12:23
  • Does this answer your question? [Generate a random sample of points distributed on the surface of a unit sphere](https://stackoverflow.com/questions/33976911/generate-a-random-sample-of-points-distributed-on-the-surface-of-a-unit-sphere) – Jacques Gaudin May 10 '22 at 21:46

0 Answers0