He, Peng

A Roboticist.

Robotic is the integration of all human knowledge, so far.


Neighbor Generator

Just a quick gist that I found very useful


class Solution(object):
    def __init__(self, board, click):
        #"""
        :param board: List[List[str]]
        :param click: List[int]
        :return: List[List[str]]
        #"""
        if not board:
            return []

        self.board = board
        self.rs, self.cs = len(self.board), len(self.board[0])
        self.dirs = [(-1, -1), (-1, 0), (-1, +1),     #  x \ y ->
                     ( 0, -1),          ( 0, +1),     #  |
                     (+1, -1), (+1, 0), (+1, +1)]     #  v
                     
    def get_valid_neighbors(self, x, y):
        neighbor = []

        for dir in self.dirs:
            ri, ci = x + dir[0], y + dir[1]
            if 0 <= ri < self.rs and 0 <= ci < self.cs:
                neighbor.append((ri, ci))

        return neighbor
Earlier Posts

Semantic Segmentation / Background Subtraction with Deep Learning

Abstract: getting into deep learning sounds big but it is quite simple. In this post, I listed the s…

In Background Subtraction, Deep Learning, TensorFlow, Keras, Python, UNETRead More
comments powered by Disqus