Categories
Ask Mathematics

Complex number proof involving angles

I need to show that (3 + i)^3 = 18 + 26i and use this to show that the angle AOC = 3AOB, where O, A, B, C are points in the plane given by O = (0, 0), A = (1, 0), B = (3, 1) and C = (18, 26). This is what […]

Categories
Development

How do I get the unique set of values for a combination of dictionary keys?

I’m using Python 3.7. I have a list of dictionaries, e.g. my_dict = [{“a”: 1, “b”: 5, “c”: 6}, {“a”: 1, “b”: 5, “c”: 2}, {“a”: 2, “b”: 1, “c”: 6}] If I want to get the unique set of values for a single key, e.g. “a”, I can do set(d[‘a’] for d in my_dict) […]

Categories
Development

How do I get the unique set of values for a combination of dictionary keys?

I’m using Python 3.7. I have a list of dictionaries, e.g. my_dict = [{“a”: 1, “b”: 5, “c”: 6}, {“a”: 1, “b”: 5, “c”: 2}, {“a”: 2, “b”: 1, “c”: 6}] If I want to get the unique set of values for a single key, e.g. “a”, I can do set(d[‘a’] for d in my_dict) […]

Categories
Development

List iteration function without returning ‘none’

I am working on an alphabet challenge function that takes a string and returns, as a string, the numeric position of each letter in the given string. If the iteration does not find a letter then nothing should be returned. thus “aaa bbb cCc” should return “1, 1, 1, 2, 2, 2, 3, 3, 3” […]

Categories
Development

Traversing a given path on a tree with labelled nodes

Suppose that we have a tree with labelled nodes where each node has a unique id and a non-unique label. A path on the tree can be described by an ordered set of labels; eg., with a path descriptor, P = [”, ‘a’, ‘a.1’, ‘a.1.3’] = “/a/a.1/a.1.3” (similar to a path under Unix). The goal […]

Categories
Development

3 point Newton Cotes Open Rule

I am new to python. Kindly help me figure out why the Convergence rate is all zero. I’ve been battling with for some hours now. I’m trying to answer this question: Do a simple mesh refinement study to find the rate of convergence for the three point Newton-Cotes Open Rule. My text function is sin(x)/x. […]

Categories
Development

Pair elements from lists of list to form a new list

I have a list of lists like the following, a = [[ [1,2], [10, 3]], [[4,5], [6, 7]]] I need to pair the inner most list elements this way, a = [[[1, 10], [2, 3]], [[4, 6], [5, 7]]]. The straighforward approach would be the following, pairings_ = [] for ind in a: pairings_.append([[x, y] […]

Categories
Development

Initialize object with type [key, value: Array] in shorthand form

Suppose I want to loop through an array of characters and build up an object which represents the frequency of each character, for example: const frequency = {}; const str = ‘stackoverflow’; for (let i = 0; i < str.length; i++) { frequency[str[i]] = (frequency[str[i]] + 1) || 1; } With the above, we would […]

Categories
Development

Convert Pandas Series of labels into Series of indirect values from corresponding columns

I have following example dataframe: N = np.arange(1, 10) df = pd.DataFrame({ ‘ref’: [ ‘a’, ‘b’, ‘c’, ‘d’, ‘c’, ‘b’, ‘a’, ‘b’, ‘c’], ‘a’: [ 1, 2, 3, 4, 5, 6, 7, 8, 9], ‘b’: [ 10, 20, 30, 40, 50, 60, 70, 80, 90], ‘c’: [ 100, 200, 300, 400, 500, 600, 700, 800, […]

Categories
Development

MultiIndex Dataframe compare one index raw against others

I have a dataframe with lists as values. index=pd.MultiIndex.from_product([[“file1”, “file2”], [“a”, “b”, “c”]]) index.names = [‘file’, ‘name’] data = [ [[1,1],[0,0]], [[],[]], [[2,2,2],[7]], [[3],[3, 3, 3]], [[],[]], [[1],[4, 4]], ] df = pd.DataFrame(data, index=index, columns=[‘col1’, ‘col2’]) df col1 col2 file name file1 a [1, 1] [0, 0] b [] [] file2 a [2, 2, 2] […]