Categories
Mastering Development

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 fins a suitable answer for my case. Here it goes: I have a 3D numpy array with "0" background and other integers as foreground. I would like to find and store the foreground voxels […]

Categories
Mastering Development

when we reshape numpy array, how is the stride size inferred?

I have an 1×1024 1-d array (flattened image). To see the image, I want to reshape its size as 32×32. I can easily achieve this by doing x.reshape(-1,32) and it works as I intended. It doesn’t screw the image. It reads the 1d array with 32-width stride each time. Say this time, there are 4 […]

Categories
Mastering Development

Recursive CTE to SUM amount column using date column as terminating condition

I have a table containing loan data including the start date, loan term, and monthly payment. CREATE TABLE [dbo].[loan]( [id] [int] IDENTITY(1,1) NOT NULL, [Starting_Date] [date] NULL, [Loan_Term] [int] NULL, [Monthly_Payment] [decimal](19, 2) NULL ) ON [PRIMARY] GO Sample Data: INSERT INTO [dbo].[loan] ([Starting_Date] ,[Loan_Term] ,[Monthly_Payment]) VALUES (‘8/1/2020’, 52, 1), (‘6/2/2010’, 64, 2500), (‘9/11/2011’, 66, […]

Categories
Mastering Development

Compare list of list with dictionary

My list of list is candidates= [[714, 1023, 768, 1078], [803, 938, 868, 995]] My dictionary is: main_dict = {(1561, 48, 1623, 105): [[[1592, 58]], [[1591, 59]], [[1585, 59]], [[1600, 58]]], (714, 1023, 768, 1078): [[[1, 5]], [[2, 6]], [[3, 3]], [[4, 3]]], (803, 938, 868, 995): [[[14, 5]], [[22, 64]], [[34, 31]], [[43, 32]]] […]

Categories
Mastering Development

Why dropping columns after joining two temp views in pyspark isn’t working, which however works with data frame joins?

I need to create tempViews out of dataframes, then i need to join these tempviews and drop the duplicate columns. So I’ve written the code as mentioned below: Data1 = [ ("xx1",34,60), ("xx2",33,80), ("xx3",37,50) ] dataSchema1 = StructType([ StructField("Name",StringType(),True), StructField("Age",IntegerType(),True), StructField("Id",IntegerType(),True) ]) Data2 = [ (60,"M",3000.60), (80,"F",3300.80), (50,"M",5000.50) ] dataSchema2 = StructType([ StructField("Id",IntegerType(),True), StructField("Gender", StringType(), […]

Categories
Mastering Development

highcharts not showing the `column` bar

I’m trying to showing chart, but it is not showing the column bar . I don’t see any error for my browser console, below is my script $(‘#complete_chart’).highcharts({ chart: { type: ‘column’, margin: 75, options3d: { enabled: false, alpha: 10, beta: 25, depth: 70 } }, title: { text: ‘Performance’, style: { fontSize: ’18px’, fontFamily: […]

Categories
Mastering Development

Parametrize a column name in Pandas

I would like to find out if it’s possible to parametrize a column name. I have an example import pandas as pd df = pd.DataFrame({‘region’:[1,2,3,4,5,6], ‘id_1’:[456, 456, 342, 987, 424, 424], ‘id_2’:[98, 87, 65, 65, 32, 43], ‘id_3’:[12, 12, 34, 34, 56, 56], ‘count’:[1,0,1,1,0,0]}) reg_id=df.groupby([‘region’, ‘id_1’])[‘count’].value_counts().unstack(fill_value=0) The idea is to introduce a line for parametrization […]

Categories
Mastering Development

Generating floating point limits at compile time via template arguments and constexpr semantics:

I’m working on a set of classes. My Function class will take a Functor class which stores a function pointer to some defined function which has an operator that will invoke the function call from the function pointer. It uses a Limit class that currently takes <int,int> for its upper and lower bounds. It has […]

Categories
Mastering Development

Assigning values to 2D array element of a struct in C

Im not sure why Im getting the output Im getting for my code, Im currently trying to assign values to a 2D array element of a struct: typedef struct maximum { int mArray[5][4]; } Max; int main(int argc, char *argv[]){ rows = 5; columns = 4; Max max; printf("%s \n", argv[1]); readFile(argv[1], max); for (int […]

Categories
Mastering Development

printing alternate fibonacci and prime no series

I am creating a series in which even position contains prime numbers and odd position contains Fibonacci numbers something like(1,2,1,3,2,5,3,7,5,11,8,13,13,17,…). I have written its code but my code is printing this(1,2,1,2,2,2,3,2,5,2,8,2,13,2,21,2,34,2,55,2,89,2,144,2,233,2,377,2,610,2,) can anyone please help me in solving this. Here is my code` class Series2{ public static void main(String args[]){ int z =1; int y=0, […]