Questions tagged [neighbours]
166 questions
1
vote
1 answer
Javascript matrix check neighbor state to find edges
i am making a virtual Hama beads tool online. (its a kids toy where you put plastic beads on a matrix and iron them to make them stick together and form a solid shape)like this one below (real hama)
So far i managed to make this work (you can try…

Alix Turcq
- 11
- 2
1
vote
1 answer
numpy store the neigborhood as new (3rd) dimension into matrix
Given a numpy array like:
L = 2
np.random.randint([-1,1],size=(L,L), dtype=int)
array([[1, -1],
[-1, 1]])
How can I transform it into an array of similar shape (efficiently)
np.random.choice([-1, 1], size=(2,2,4))
array([[[-1, -1, 1, 1],
…

Georg Heiler
- 16,916
- 36
- 162
- 292
1
vote
1 answer
R: number of adjacent/neighbour cells in raster
I have a raster grid of Chile and want to compute the number of terrestrial cells in
the neighbourhood. Is there a way in R to compute the number of adjacent/neighbour cells in a raster? So most cells should get the value 8 (due to 8 surounding…

FreddySorbe
- 125
- 5
1
vote
2 answers
How to combine Python list elements on either side of i when i mets a certain condition
There is a similar question already on Stack Overflow see link, but I am having problems referencing the item before i. I'm working with a list of strings, and only need to combine neighboring strings in the list when a certain string starts with…

Erik
- 19
- 5
1
vote
1 answer
Numpy: value substitution according to neighbours
I need to change value for items in a numpy array on the basis of their neighbours values.
More specifically, let's suppose that I have just 3 possible values for each item in a numpy representing an image. Let's suppose my numpy is the following…

gazzella
- 11
- 1
1
vote
1 answer
Connect turtles who are within a certain radius
I use the nw extension in NetLogo to create a network.
My aim is the following:
Check if any turtles are close by
If any turtles are close by (I tried with next 3 patches, but that might change), connect to them + there is an upper limit of…

Hannah H.
- 266
- 3
- 14
1
vote
2 answers
Efficient neighbourhood search in numpy ndarray instead of nested conditional for loops
Although there are many instances of the question: "What is the numpy alternative to nested for loops", I was unable to find a suitable answer for my case. Here it goes:
I have a 3D numpy array with "0" background and other integers as foreground. I…

lvl0l27
- 47
- 6
1
vote
1 answer
Move turtle to a patch with some neighbors of same type of turtle and stay there
I tried to move a turtle to a patch where there 2 turtles with the same type (e.g income) as its neighbor and stay there. I did the following code
to set-move
let target []
ask turtles with [income = "low"]
[ let potential-target1 patches with…

Dudi Pul
- 149
- 8
1
vote
2 answers
Determining a JComponent's immediate neighbors in a FlowLayout
I have a JPanel that uses a FlowLayout and contains many JButtons. The buttons are in a 2-dimensional grid (by the FlowLayout). The JPanel can be resized, and, of course, when it is, the location of the buttons in the grid changes (although the…

Paul Reiners
- 8,576
- 33
- 117
- 202
1
vote
0 answers
How to obtain a set of closest points surrounding a specific point in a map?
I have a set of points on a map.
For each point (say 'a'), i want to obtain n (say 5) nearest neighbours that surround the point.
Currently, I make a list of euclidean distance from 'a' to other points .Then I sort the list and choose 'n' smallest…

lxuser
- 11
- 3
1
vote
3 answers
Python Numpy Array geht values of neighbours
I want to get all neighbour values of a np.array.
The array looks like:
x = np.array([ [1, 2, 3, 4 ],
[5, 6, 7, 8],
[9, 10, 11, 12],
[13, 14, 15, 16] ])
What I have is:
i = 2
j = 2
n = x[i,j-1],…

Pablo
- 99
- 1
- 8
1
vote
1 answer
How to fix Wrong Accuracy & R -Square?
I try to practice Linear Regression by analyzing data file Google Apps Store to predict Rating, the file csv is on Kaggle.
After cleaning and trying to apply KNeighborsRegressor to run the model, as the results, the accuracy and r-squared are too…

Thoa Ng
- 49
- 1
- 7
1
vote
2 answers
How to count neighbouring cells in a numpy array using try-except?
I have a numpy array:
x = np.random.rand(4, 5)
I would like to create an array showing how many neighbouring values are there for each value in the original array. By neighbouring I mean:
example=np.array([[0,1,0,0,0],
…

zabop
- 6,750
- 3
- 39
- 84
1
vote
1 answer
Netlogo: sum within a neighborood
I need some help. My issue is the following
I want to solve the following formula
sum (Zi - Zj)^2 where Zi is a constant for an individual i and Zj is the value for a generic individual j that is within a neighborood with radius = 1 of the…

Miki
- 129
- 1
- 6
1
vote
1 answer
Python 3 how to detect and replace neighbors in array
I have a nested lists. Example:
list=[[1,1,1,3,3,1,1],
[2,1,1,2,1,1,2],
[3,0,1,1,1,1,3],
[1,7,1,8,1,0,1]]
I want to identify and change the same neighbors(left,right,top,bottom) at the point I choose in this list. Without using…

Kamil karaçelik
- 13
- 2