Categories
Mastering Development

Calculate geographic distance between points using NetTopologySuite

I am trying to calculate distance between two points using NetTopologySuite. Since I am referencing Microsoft documentation, I Came up with following GeometryExtension and GeometryHelper classes: public static class GeometryExtensions { private static readonly CoordinateSystemServices _coordinateSystemServices = new CoordinateSystemServices(new Dictionary<int, string> { // Coordinate systems: [4326] = GeographicCoordinateSystem.WGS84.WKT, // CRS for Denmark ESPG 25832. Source: […]

Categories
Mastering Development

How can we Sort a dictionary

As a part of key I am storing a List and in Value I want to store max and min values of that list. Later there will be many lists like that. I need to sort for the dictionary having minimum possible maximum element value and minimum possible minimum element value Something like var map= […]

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

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

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

How to add limited hints when programming a quiz?

I am making a trivia quiz that allows users to solve 10 trivia questions and get a score. I am planning to provide the users 3 hints and print out Sorry! You used all the hints. when the user uses all 3 hints. How do I do that? I know I would need to use […]

Categories
Mastering Development

Rewriting a loop with Rccp

I am a novice Rcpp user. I want to fasten my for loop which uses several entities from r environment, and updates two vectors through iterations. The problem is that this is my first time facing c or c++ so I do not understand how to write rcpp with inline packages. Here is the reproducible […]

Categories
Mastering Development

Syntax Error: ‘return’ outside function: my indentations seem to be correct

So first of all im writing a program that will total up all of the values in a list / array and heres what i got so far def go( ann ): total = 0 for i in range(0,len(ann)): total = total+ann[i] return total print ( go( [-99,1,2,3,4,5,6,7,8,9,10,12345] ) ) print ( go( [10,9,8,7,6,5,4,3,2,1,-99] ) […]

Categories
Mastering Development

How to get key from the value of dictionary

I have the following set of rules for grading system if 25 < score <= 30, grade = A. if 20 < score <= 25, grade = B. if 15 < score <= 20, grade = C. if 10 < score <= 15, grade = D. if 5 < score <= 10, grade = E. […]

Categories
Mastering Development

Arrange data frame columns by class

Good afternoon , Assume we have the following dataset : dput(head(cylinder)) structure(list(X19910108 = c("19910109", "19910104", "19910104", "19910111", "19910104", "19910111"), X126 = c("X266", "B7", "T133", "J34", "T218", "X249"), TVGUIDE = c("TVGUIDE", "MODMAT", "MASSEY", "KMART", "MASSEY", "ROSES"), X25503 = c(25503L, 47201L, 39039L, 37351L, 38039L, 35751L), YES = c("YES", "YES", "YES", "NO", "YES", "NO"), KEY = c("KEY", "KEY", […]