Skip to content

Instantly share code, notes, and snippets.

@masterdezign
Last active April 20, 2024 16:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masterdezign/4f09e4444d0330e2984c2e11c593386e to your computer and use it in GitHub Desktop.
Save masterdezign/4f09e4444d0330e2984c2e11c593386e to your computer and use it in GitHub Desktop.
import numpy as np
def spirals(n_samples=400):
N = n_samples
theta = np.sqrt(np.random.rand(N))*2*np.pi
r_a = 2*theta + np.pi
data_a = np.array([np.cos(theta)*r_a, np.sin(theta)*r_a]).T
x_a = data_a + np.random.randn(N,2)
r_b = -2*theta - np.pi
data_b = np.array([np.cos(theta)*r_b, np.sin(theta)*r_b]).T
x_b = data_b + np.random.randn(N,2)
res_a = np.zeros((N,1), dtype='uint8')
res_b = np.ones((N,1), dtype='uint8')
x = np.concatenate([x_a, x_b], axis=0)
res = np.concatenate([res_a, res_b], axis=0).reshape(-1)
return x, res
Xdata, ydata = spirals()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment