Mapping 2 vectors – help to vectorize

Oh! One other option: since you’re looking for close correspondences between two sorted lists, you could go through them both simultaneously, using a merge-like algorithm. This should be O(max(length(xm), length(xn)))-ish. match_for_xn = zeros(length(xn), 1); last_M = 1; for N = 1:length(xn) % search through M until we find a match. for M = last_M:length(xm) dist_to_curr … Read more

GPS coordinates in degrees to calculate distances

Why don’t you use CLLocations distanceFromLocation: method? It will tell you the precise distance between the receiver and another CLLocation. CLLocation *locationA = [[CLLocation alloc] initWithLatitude:12.123456 longitude:12.123456]; CLLocation *locationB = [[CLLocation alloc] initWithLatitude:21.654321 longitude:21.654321]; CLLocationDistance distanceInMeters = [locationA distanceFromLocation:locationB]; // CLLocation is aka double [locationA release]; [locationB release]; It’s as easy as that.

Nested Dictionary to MultiIndex pandas DataFrame (3 level)

Using an example of three level dict In [1]: import pandas as pd In [2]: dictionary = {‘A’: {‘a’: {1: [2,3,4,5,6], …: 2: [2,3,4,5,6]}, …: ‘b’: {1: [2,3,4,5,6], …: 2: [2,3,4,5,6]}}, …: ‘B’: {‘a’: {1: [2,3,4,5,6], …: 2: [2,3,4,5,6]}, …: ‘b’: {1: [2,3,4,5,6], …: 2: [2,3,4,5,6]}}} And the following dictionary comprehension based on the one … Read more

How to bind Dictionary to ListBox in WinForms

var choices = new Dictionary<string, string>(); choices[“A”] = “Arthur”; choices[“F”] = “Ford”; choices[“T”] = “Trillian”; choices[“Z”] = “Zaphod”; listBox1.DataSource = new BindingSource(choices, null); listBox1.DisplayMember = “Value”; listBox1.ValueMember = “Key”; (Shamelessly lifted from my own blog: Bind a ComboBox to a generic Dictionary.) This means you can use SelectedValue to get hold of the corresponding dictionary … Read more

How to search if dictionary value contains certain string with Python

You can do it like this: #Just an example how the dictionary may look like myDict = {‘age’: [’12’], ‘address’: [’34 Main Street, 212 First Avenue’], ‘firstName’: [‘Alan’, ‘Mary-Ann’], ‘lastName’: [‘Stone’, ‘Lee’]} def search(values, searchFor): for k in values: for v in values[k]: if searchFor in v: return k return None #Checking if string ‘Mary’ … Read more