#๐ how to graph binary 2d array of pixels?
108 messages ยท Page 1 of 1 (latest)
@queen vine
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
what library are you using?
for graphing
matplotlib
are you using jupter notebooks?
nope
are you using data science based libraries?
alright, you can simply convert your pixels to numpy array
they are in one
You'll probably want to use matplotlib.pyplot.imshow.
the colormap is seperate tho
It's by default normalised.
and you can set the vmin and vmax manually
and the cmap
how do I fix this py img = ax.imshow( img, extent=[*big_range, *big_range], aspect="equal", interpolation="gaussian", origin="lower", )
I have to run it 5 times for it to work
img = network.calculate_outputs(pixels)
#ax.pcolor(img, cmap='binary')
#img = ax.pcolormesh(img, cmap='binary')
custom_cmap = matplotlib.colors.ListedColormap(["#ADD8E6", "white"])
img = ax.imshow(
img,
cmap=custom_cmap,
extent=[*big_range, *big_range],
aspect="equal",
interpolation="gaussian",
origin="lower",
)```
You look like you know more about matplotlib than I do.
also half of the weights act weird with the graph so I dont think that graphs it correctly
idk what that stuff even does
just combined and copied stuff from stackoverflow
i know it is how I am graphing it since if I scatter plot it, it works
I cant make this shape with the imshow
from matplotlib import pyplot as plt
...
plt.imshow(arr, cmap='gray')
plt.show()```This is all I'd end up doing.
But yeah, if it's not liking the lists, convert to a numpy array and it should work fine.
points = np.column_stack((x, y, colors.astype(int)))
xs, ys = np.meshgrid(np.linspace(*big_range), np.linspace(*big_range))
pixels = np.stack((xs.T, ys.T), axis=2)
from scipy.spatial import ConvexHull
graph = None
def accuracy():
nonlocal graph
if graph:
graph.remove()
pointsX = []
pointsY = []
colors = []
total = 0
for point in points:
px, py, value = point
output = network.calculate_output((px, py))
pointsX.append(px)
pointsY.append(py)
colors.append(output == value)
total += np.array(output > 0).astype(int) == value
img = network.calculate_outputs(pixels)
graph = ax.scatter(pointsX, pointsY, np.array(colors) * 100, c="black")
img = network.calculate_outputs(pixels)
custom_cmap = matplotlib.colors.ListedColormap(["#ADD8E6", "white"])
img = ax.imshow(
img,
cmap=custom_cmap,
extent=[*big_range, *big_range],
aspect="equal",
interpolation="gaussian",
origin="lower",
)
dont question the nonlocal
If you know enough to use it and that it even exists, I'm going to assume you know when and where to use it.
i just am using it cause I am testing
@whole viper maybe it is the way I am getting the pixels? py points = np.column_stack((x, y, colors.astype(int))) xs, ys = np.meshgrid(np.linspace(*big_range), np.linspace(*big_range)) pixels = np.stack((xs.T, ys.T), axis=2)
I want pixels to be [(1, 2), (4, 3) ....]
and then after pasted through my neural network to be [[1,1,1],[0,0,1],...]
Oh. That's not what I thought your data looked like.
is there a way to flatten everything except the inner most (1,2),(1,2)
If you have a y by x grid of bools, and you want the location of all the 1s, you can use numpy.where(arr) that'll give you ((y, y, y, y), (x, x, x, x)) style data, which you can feed into an array then use .T on it.
cause pixels ... [[-2.85714286e-02 -2.00000000e-01] [-2.85714286e-02 -1.71428571e-01] [-2.85714286e-02 -1.42857143e-01] [-2.85714286e-02 -1.14285714e-01] [-2.85714286e-02 -8.57142857e-02] [-2.85714286e-02 -5.71428571e-02] [-2.85714286e-02 -2.85714286e-02] [-2.85714286e-02 -2.77555756e-17] [-2.85714286e-02 2.85714286e-02] [-2.85714286e-02 5.71428571e-02] [-2.85714286e-02 8.57142857e-02] [-2.85714286e-02 1.14285714e-01] [-2.85714286e-02], [[-2.85714286e-02 -2.00000000e-01] [-2.85714286e-02 -1.71428571e-01] [-2.85714286e-02 -1.42857143e-01] [-2.85714286e-02 -1.14285714e-01] [-2.85714286e-02 -8.57142857e-02] [-2.85714286e-02 -5.71428571e-02] [-2.85714286e-02 -2.85714286e-02] [-2.85714286e-02 -2.77555756e-17] [-2.85714286e-02 2.85714286e-02] [-2.85714286e-02 5.71428571e-02] [-2.85714286e-02 8.57142857e-02] [-2.85714286e-02 1.14285714e-01] [-2.85714286e-02
i think the problem is calculating all the pixels
if I have a range from 0->1 (through linspace) how do I get all diferent pairs like (0.01, 0.01), (0.02, 0.01), (0.03, 0.01), ... (0.01, 0.02),,,
What's the population?
!d numpy.linspace
numpy.linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None, axis=0, *, device=None)```
Return evenly spaced numbers over a specified interval.
Returns *num* evenly spaced samples, calculated over the interval [*start*, *stop*].
The endpoint of the interval can optionally be excluded.
Changed in version 1.16.0: Non-scalar *start* and *stop* are now supported.
Changed in version 1.20.0: Values are rounded towards `-inf` instead of `0` when an integer `dtype` is specified. The old behavior can still be obtained with `np.linspace(start, stop, num).astype(int)`
num
Give me an idea.
Is the order of the pairs significant?
no
Worst case scenario, how large is num?
150
Because you could use itertools.combinations.
if it is too slow I would lower num
is that like faster?
how do I use it
only have to calculate it once
my code didnt realize I only needed to do it once
!d itertools.combinations
itertools.combinations(iterable, r)```
Return *r* length subsequences of elements from the input *iterable*.
The combination tuples are emitted in lexicographic ordering according to the order of the input *iterable*. So, if the input *iterable* is sorted, the output tuples will be produced in sorted order.
Elements are treated as unique based on their position, not on their value. So if the input elements are unique, there will be no repeated values in each combination.
Roughly equivalent to:
!e py import itertools data = [1, 2, 3] result = [*itertools.combinations(data, 2)] print(result)
@whole viper :white_check_mark: Your 3.12 eval job has completed with return code 0.
[(1, 2), (1, 3), (2, 3)]
Hang on..
itertools.product(*iterables, repeat=1)```
Cartesian product of input iterables.
Roughly equivalent to nested for-loops in a generator expression. For example, `product(A, B)` returns the same as `((x,y) for x in A for y in B)`.
The nested loops cycle like an odometer with the rightmost element advancing on every iteration. This pattern creates a lexicographic ordering so that if the inputโs iterables are sorted, the product tuples are emitted in sorted order.
To compute the product of an iterable with itself, specify the number of repetitions with the optional *repeat* keyword argument. For example, `product(A, repeat=4)` means the same as `product(A, A, A, A)`.
I've used this before, but I'm having a stupid brain moment.
Oh, right.
!e py import itertools data = [1, 2, 3] result = [*itertools.product(data, repeat=2)] print(result)
so itertools.product(np.linespace?
@whole viper :white_check_mark: Your 3.12 eval job has completed with return code 0.
[(1, 1), (1, 2), (1, 3), (2, 1), (2, 2), (2, 3), (3, 1), (3, 2), (3, 3)]
There we go. It needed it as a keyword argument, because *iterables.
for a in data:
for b in data:
(a, b)```Basically.
oh darn it File "c:\Users\jacob\AppData\Local\Programs\Python\Python311\Lib\site-packages\matplotlib\axes_axes.py", line 5665, in imshow
im.set_data(X)
File "c:\Users\jacob\AppData\Local\Programs\Python\Python311\Lib\site-packages\matplotlib\image.py", line 710, in set_data
raise TypeError("Invalid shape {} for image data"
TypeError: Invalid shape (10000,) for image data
thats why I had ugly meshgrid
but then the input to my neural network is broken
okay so I have a bunch of pixels [(1,2),(2,2),(3,2)...] and I have whether to color the pixel white or black [0,1,0,...] @whole viper
how do I graph that now
wait what if every 100 index it becomes a new array so that the black and white are 2d
[[0,1,0,0,0,0,0,... (100 times)],
[0,1,0,0,0,0,0,... (100 times)],
then maybe imshow can graph that
but that breaks the order....
nvm the pixels do need order
!d numpy.meshgrid
numpy.meshgrid(*xi, copy=True, sparse=False, indexing='xy')```
Return a tuple of coordinate matrices from coordinate vectors.
Make N-D coordinate arrays for vectorized evaluations of N-D scalar/vector fields over N-D grids, given one-dimensional coordinate arrays x1, x2,โฆ, xn.
Changed in version 1.9: 1-D and 0-D cases are allowed.
how do I do this @whole viper ?
I don't understand how to help you at the present time. I don't understand the problem as it is being presented.
let me test some stuff
.reshape(100, -1)
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.