Categories
Mastering Development

What is the reason of making a : subscription on Python variables?

I found this code at Stack Overflow: input_filename = "to_modify.xlsx" wb = load_workbook(input_filename) # Get first sheet sh: worksheet = wb[wb.sheetnames[0]] The link is here: How to change font size in Python OpenPyXL So, I tried in a simplified way as: str = [1, 2, 3, 4] bo: fo = str[str[0]] And it gave me […]

Categories
Mastering Development

Using z-score how do I flag(highlight) outliers in a specific column in python

In my df below, I want to : identify and flag the outliers in col_E using z-scores separately explain how to identify and flag the outliers using z-scores in two or more columns, for example col_D & col_E See below for the dataset import pandas as pd # intialise data of lists df = { […]

Categories
Mastering Development

Reverse an iterator multiple times in Python

I am trying to reverse the same iterator several times, using the reversed function. For instance, with the code: iterator = range(3) N = 5 k = 0 out = [] while k < N: for i in iterator: out.append(i) iterator = reversed(iterator) k += 1 print(out) I would want/expect to have the output: [0, […]

Categories
Mastering Development

`Error in cor(data) : ‘x’ must be numeric` in correlation code

#Data Import data<-read.csv("D:\\general\\insurance.csv") #Data Exploration(EDA) str(data) summary(data) #Data Preparation #Outlier Detection & Treatment #Box-Plot outlier_values <- boxplot.stats(data$charges)$out # outlier values par(mar=c(2,2,2,2)) boxplot(data$charges, main="charges", boxwex=0.1) mtext(paste("Outliers: ", paste(outlier_values, collapse=",")), cex=0.6) user defined function for creating descriptive statistics stats <- function(x) { iqr=IQR(x,na.rm=T) q1<-quantile(x,0.25,na.rm=T) q2<-quantile(x,0.5,na.rm=T) q3<-quantile(x,0.75,na.rm=T) UC<-q3+1.5*iqr LC<-q1-1.5*iqr min<-min(x,na.rm=T) max<-max(x,na.rm=T) return(c(q1=q1, q2=q2, q3=q3,UC=UC, LC=LC, min=min, max=max)) } […]

Categories
Mastering Development

Accumulate sliding windows relative to origin

I have an array A with the shape (3,3) which can be thought of as the sliding window view of an unkown array with the shape (5,). I want to compute the inverse of windowing the array with the shape (5,). The adjoint operation of this will be summation. What I mean is that I […]

Categories
Mastering Development

How can I extract features from superpixels with Haralick derivation based on GLCM?

1 – I am extracting features for superpixels and one of the extractions that I need to implement is the extraction of Haralick features from the gray-level Co-occurrence Matrix GLCM (Gray-Level Co-occurrence Matrix). In this sense, I understood that first I have to extract Haralick and then apply it to GLCM to find the contrast, […]

Categories
Mastering Development

indexing rows and columns in numpy

a = np.array(list(range(16).reshape((4,4)) array([[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11], [12, 13, 14, 15]]) Say I want the middle square. It’d seem reasonable to do this: a[[1,2],[1,2]] but I get this: array([5, 10]) This works, but seems inelegant: a[[1,2],:][:,[1,2]] array([[5, 6], [9, 10]]) So my questions are: […]

Categories
Mastering Development

Ip Black list Outcome

I have the following php code to specify ip blacklist ranges via a blacklist.dat file. How do I specify the outcome? ie I would like all the blacklisted IPs to go to a specific url. Any assistance would be appreciated. Thanks in advance <?php # Blacklist check snippet class IpList { private $iplist = array(); […]

Categories
Mastering Development

Pick a slice from R array according to coordinates

I have two vectors x and y of coordinates and a 3D array A in R. I want to produce a matrix, where the i’th row is A[x[i], , y[i]]. If A was 2D, I believe I could use A[cbind(x,y)]. For the 3D array, I think the following works, but it’s kind of slow: sapply(1:length(x), […]

Categories
Mastering Development

I’d like to wrap std::array to create a circular array but how to provide aggregate initialization

With std::array you can do std::array<int,3> v = {1,2,3}; But I want to provide a wrapper template <typename T, int n> circular_array { auto operator[](size_t i){ return m_data[i%n]; } // TODO forward all other methods directly except “at“ which we don’t need private: std::array<t,n> m_data; } but I lose the aggregate initialization that I had […]