I have an array of variable length filled with 2d coordinate points (coming from a point cloud) which are distributed around (0,0) and i want to convert them into a 2d matrix (=grayscale image).
# have
array = [(1.0,1.1),(0.0,0.0),...]
# want
matrix = [[0,100,...],[255,255,...],...]
how would i achieve this using python and numpy
Looks like matplotlib.pyplot.hist2d
is what you are looking for.
It basically bins your data into 2-dimensional bins (with a size of your choice). here the documentation and a working example is given below.
import numpy as np
import matplotlib.pyplot as plt
data = [np.random.randn(1000), np.random.randn(1000)]
plt.scatter(data[0], data[1])
Then you can call hist2d
on your data, for instance like this
plt.hist2d(data[0], data[1], bins=20)
note that the arguments of hist2d
are two 1-dimensional arrays, so you will have to do a bit of reshaping of our data prior to feed it to hist2d
.