Good evening I have been writing some python code for my numerical methods course, and I’m getting very bad results from the last section, leading to the message "RuntimeWarning: invalid value encountered in double_scalars". Basically, what the code wants to do is A) Define a couple fields ( T, phi) ; B) Define a matrix ..

#### Category : recursion

I wanted to get permutations of a list of numbers without using any external library. I have written the code below class Solution: def permute(self, nums: List[int] , s = 0 , ans = [] ) -> List[List[int] ]: l = len(nums) if l == 0: return 0 if l == 1: return [nums] if ..

I was solving question of merging two binary trees in LeetCode using recursion but recursion is not working. But recursion is not working in my code.I want to know where I am making mistake. class Solution: def merge(self, root1, root2): if root1 != None and root2 != None: root1.val += root2.val if root1 == None ..

I have been running into an issue when calling a flask api in parallel (problem occurs with only 2 instances). In my full code, I request data from a table and then create a json tree that will then be displayed on the front-end. I noticed that my trees were looking strange, the first one ..

I’m trying to parse a nested JSON in order to insert values into SQL table where the keys would be column names. Here’s a sample of my data: json = {‘inquiry_date’: ‘2021-01-14’, ‘address’: {‘city’: ‘Warsaw’, ‘zip_code’: ’20-200′, ‘country’: ‘Poland’, ‘house_no’: ’22’, ‘street’: ‘Some-Street’}, ‘insert_date’: ‘2020-12-20’, ‘is_active’: False} and here’s parsing function: def parse_json(json): for k, ..

I’m trying to write a code for solving sudoku puzzles, which takes a 9×9 NumPy array as input, and returns a 9×9 NumPy array as output. This is my code: def possible(x,y,n, matris): for i in range(0, 9): if matris[x][i] == n: return False for i in range(0, 9): if matris[i][y] == n: return False ..

I am working on a self-defined class to solve the problem, which is pretty common format in leetcode. The problem is as: Path with Maximum Sum (hard) # Find the path with the maximum sum in a given binary tree. Write a function that returns the maximum sum. A path can be defined as a ..

I am learning coding by myself. I am taking learning recursive function from online resources, and as an exercise, I came across this one exercise where I am tasked to create a recursive function to see if numbers in the list are in order. The exercise says not to use loops and not to use ..

I have to use recursion to compute the value of the following formulas: m = 1.4 *t + 1.2*z + 0.8*l + 0.1*o o = 1.0 *g + 1.3 *g + 1.3 *f + 0.2 *t t = 0.9*g + 0.9 *f l = 1.8 *t + 1.7 *g + 0.7 *o With f= 1.4, ..

I am solving the problem of finding the sizes of all islands existing in an nxm matrix. I used a recursive method and have no clue what the bug in my code is that is causing the maximum recursion depth error. Thank you in advance ðŸ™‚ def riverSizes(matrix): returnList = [] for row in range(len(matrix)): ..

## Recent Comments