I need a set of random coordinate points from different equations. Here's how I did it for the equation of a circle:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
I read here that looping in list will be faster than looping in numpy(is it true?) so i created list then coverted into numpy array
X_pos=[]
X_neg = []
num_measurements =3
num_examples = 1000
Create random x coordinates in range (-1,1). Thousand circles with three points each
for i in range(num_examples):
X_pos.append((2*np.random.random(num_measurements))-1)
X_neg.append((2*np.random.random(num_measurements))-1)
X_pos = np.array(X_pos)
X_neg = np.array(X_neg)
X = np.hstack((X_pos,X_neg))
Calculate y coordinates:
Y_pos = np.sqrt(1-np.power(X_pos,2))
Y_neg = (np.sqrt(1-np.power(X_neg,2)))*(-1)
Y= np.hstack((Y_pos,Y_neg))
Q1. Is there a shorter and efficient way to do this?
Q2. Is there a library that can do all or some_parts of this code?