I couldn’t find any answer to this specific case. Say I want to create a scatter plot from the following data:
JavaScript
x
3
1
y = np.array([[1,2,3,6,5,3,4,2],[1,2,4,5,5,3,3,2]])
2
X = np.array([[86],[82]])
3
Where all the values of y[0]
are the correseponding values of X[0]
(86) and so on. I know I can just use numpy repeat
function but I thought maybe there’s any other more feasilbe option? I’ve tried to reshape the any of the arrays but it didn’t help. Any ideas?
Advertisement
Answer
I really like the tile function from numpy. I dont think there is a way around of “enlarging” X[i] to make it match the length of y[i]
JavaScript
1
9
1
import numpy as np
2
import matplotlib.pyplot as plt
3
4
y = np.array([[1,2,3,6,5,3,4,2],[1,2,4,5,5,3,3,2]])
5
X = np.array([[86],[82]])
6
7
for i in range(len(X)):
8
plt.plot(np.tile(X[i], len(y[i])), y[i], '.')
9