Skip to content

Instantly share code, notes, and snippets.

@RashidLadj
RashidLadj / Medianfilter.py
Last active January 4, 2022 15:47
Apply a length-k median filter to a 1D array x
import numpy as np
import cv2 as cv
def medianFilter(x, k):
"""
Apply a length-k median filter to a 1D array x.
Boundaries are extended by repeating endpoints.
this is the equivalent of opencv Median for 2D array
"""
if k == 1 :
@RashidLadj
RashidLadj / string_split.cpp
Created September 6, 2021 16:47
implementation of a simple function which is used to split a character string by taking the delimiter
#include <iostream>
#include <string>
#include <vector>
using namespace std;
vector<string> split (const string &s, const string &delimiter);
int main() {
string myString = "We_try_to_split_string";
@RashidLadj
RashidLadj / mainTree.cpp
Last active August 16, 2021 11:09
class template representing the tree structure that can take any type in data
#include "treeClass.hpp"
ostream& operator<<(ostream& os, const vector<int>& myVector){
os << "{ ";
for (int i = 0; i < myVector.size(); i++){
if (i!=0)
os << ", " ;
os << myVector[i] << " " ;
}
os << "}";
#include <iostream>
#include <vector>
using namespace std;
/** Method 1 - Using friend operator in struct or class with public attributes **/
struct vec2D_1 {
public: vector<vector<int>> v;
vec2D_1(vector<vector<int>> v_){
@RashidLadj
RashidLadj / _ keyboart shortcut clear cmd
Last active September 6, 2023 21:44
this is a script to create keyboard shortcut to clear cmd and windows_terminal and vscode_terminal in Windows
this is a script to create keyboard shortcut to clear cmd and windows_terminal and vscode_terminal in Windows
@RashidLadj
RashidLadj / intersect2D.py
Last active October 16, 2020 15:08
Python function to find the intersection between two 2D (or nD) numpy arrays, i.e. intersection of rows
import numpy as np
def intersect2D(Array_A, Array_B):
"""
Find row intersection between 2D numpy arrays, a and b.
"""
# ''' Using Tuple ''' #
intersectionList = np.asarray([x for x in Array_A for y in Array_B if(tuple(x) == tuple(y))])
@RashidLadj
RashidLadj / intersect2D_with_Index.py
Last active February 4, 2021 11:51
Python function to find the intersection between two 2D numpy arrays with index in each array, i.e. intersection of rows
import numpy as np
def intersect2D(Array_A, Array_B):
"""
Find row intersection between 2D numpy arrays, a and b.
Returns another numpy array with shared rows and index of items in A & B arrays
"""
# [[IDX], [IDY], [value]] where Equal
# ''' Using Tuple ''' #
IndexEqual = np.asarray([(i, j, x) for i,x in enumerate(Array_A) for j, y in enumerate (Array_B) if(tuple(x) == tuple(y))]).T