#πŸ”’ is that better and if yes why and what can i improve

39 messages Β· Page 1 of 1 (latest)

pine path
#

y_coords = np.arange(0, num_rows) * target_height
x_coords = np.arange(0, num_cols) * target_width

Use meshgrid to create all combinations of coordinates

y_grid, x_grid = np.meshgrid(y_coords, x_coords, indexing='ij')

Iterate through each square coordinate and extract the square

for y, x in zip(y_grid.flat, x_grid.flat):

simple coyoteBOT
#

@pine path

Python help channel opened

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.

pine path
#

the old one for row in range(90, height+1, 60):
cv2.line(result, (0, row), (width, row), (255, 0, 0), 3)
for cal in range(90, width+1, 60):

stable mural
#
import itertools

x_coords = ...
y_coords = ...

for x, y in itertools.product(x_coords, y_coords):
  ...
#

If you want to do it with a single loop

#

@pine path

pine path
#

is it just for prefence or faster then the numpy version

stable mural
#

Well you are already looping through each item, so numpy will not make that much of a difference

#

So might as well write it in a way that is simpler to understand

#

What you are looking for is a "cartesian product". This is implemented in itertools, but can also be done with a nested for loop.

pine path
stable mural
#

Well yeah, but you are doing for y, x in zip(y_grid.flat, x_grid.flat): anyways

#

And in that loop you do some operations probably, so the itertools.product will not make the program much slower

#

If you want to remove loops, then you have to use some numpy function that can be performed on every pair of coordinates

pine path
#

i testet it and it is about the same

pine path
stable mural
#

I don't know what you are trying to do

lost perch
#

I don't know what you are comparing to so no clue about it being "better" or not, but it is really bad objectively speaking - you really shouldn't be iterating over things when using numpy

pine path
#

so what I want to do is. I have an image I this Image is in grayscale and i want to tear it on subimages with the size 90*90 and then get the average the pixels within an subimage @lost perch and @stable mural

lost perch
#

can't you just use a 2d convolutional operation for that?

stable mural
#

Yeah sounds like convolution πŸ˜›

pine path
#

What import do i need for that

stable mural
#

Could use scipy for that

pine path
#

ty

lost perch
#

might take a little trial and error to get the right shape if you never touched it before

pine path
#

the kernel should be 90*90 with each value is 1/90

#

right?

stable mural
#

1/(90*90)

pine path
#

yeah

pine path
#

@lost perch or @stable mural does this modul also have a step size canΒ΄t like a convlutional layer in keras

stable mural
#

It does not

pine path
#

ah that is wonderfull XD

#

so how can i how separate separatete the image with that funktion in this size num_rows = image.shape[0] // target_height
num_cols = image.shape[1] // target_width

pine path
# stable mural It does not

it is not the dont want to make a simple feater map with the same size but rather somthing like averege pooling

#

found something

#

ty it kinda safed me 0,04 FPS tbh that is because i had to make a another for loop which i might beable to get rid of later

simple coyoteBOT
#
Python help channel closed

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.