Categories

How to iterate through 2 lists like this? [closed]

How do I do it in Python? Input: num = [1, 2, 3] alpha = [a, b, c] Output: [1, a] [1, a, b] [1, a, b, c] [1, b, c] [1, c] [1, 2, a] [1, 2, a, b] … [1, 2, c] … … [3, a] [3, a, b] … [3, c] Constraints: […]

Categories

Lodash reduce with includes or orderBy iteratee use cases

From the lodash documentation for reduce: _.reduce(collection, [iteratee=_.identity], [accumulator]) Reduces collection to a value which is the accumulated result of running each element in collection thru iteratee, where each successive invocation is supplied the return value of the previous. If accumulator is not given, the first element of collection is used as the initial value. […]

Categories

Why is complex multiplication nearly as fast as integer multiplication in python?

I was under the impression that complex number multiplication takes longer than real number multiplication, since it requires 3 multiplications. However I tried the following: a, b = 3, 4 c, d = 5, 6 print(a*c – b*d, a*d + b*c) e = 3+4j f = 5+6j print(e*f) %timeit a*c – b*d %timeit a*d + […]

Categories

Change javascript Object attributes to nested object values

so I have an object with the following format const objA = { A: {a: 1, b: 2}, B: {a: 3, b: 4}, } And I’m trying to to obtain a new object with the structure below objB = { A: 1, B: 3, } where the value of each key it’s the value of […]

Categories

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

Algorithm: Counting elements of Polyomino coverings

Given a set of free Polyominoes $\mathcal{P}$ (translation, flipping and rotating of pieces is allowed) and a test shape $S$ that is also a valid Polyomino, I am trying to find an algorithm $f(S, \mathcal{P}) : S \times \mathcal{P} \to (\mathcal{P}, \mathbb{N})$ that counts the number of times entries in $\mathcal{P}$ are used to generate […]

Categories

Algorithm: Counting elements of Polyomino coverings

Given a set of free Polyominoes $\mathcal{P}$ (translation, flipping and rotating of pieces is allowed) and a test shape $S$ that is also a valid Polyomino, I am trying to find an algorithm $f(S, \mathcal{P}) : S \times \mathcal{P} \to (\mathcal{P}, \mathbb{N})$ that counts the number of times entries in $\mathcal{P}$ are used to generate […]

Categories

how to open jupyter widget in a separate window

%matplotlib qt from ipywidgets import interact, interactive, fixed, interact_manual import ipywidgets as widgets import matplotlib.pyplot as plt import numpy as np def f(m, b): plt.figure(2) x = np.linspace(-10, 10, num=1000) plt.plot(x, m * x + b) plt.ylim(-5, 5) plt.show() interactive_plot = interactive(f, m=(-2.0, 2.0), b=(-3, 3, 0.5)) interactive_plot This just plots all the lines in […]

Categories

How do I add a second plot behind the first one in matplotlib.pyplot? It’s either on top or invisible

I want to make a bar graph showing current measurements compared to a one-month moving average, by placing blue bars for current data (‘a’) on top of slightly wider grey bars for the one-month average (‘b’). Here is the simplest version of my code: import matplotlib.pyplot as plt import pandas as pd import numpy as […]

Categories

how do i destructure an object only when key is present

how do I destructure an object only when key is present in the object or should I say destructuring using conditionals const arts = { a: 23, b: 3, c: 5} const {a, d} = arts console.log(d) // result produces an error on execution I want a code where “d” won’t be destructured if it’s […]