algorithm

Why is this simple Python program not giving the correct output?

Why is this simple Python program not giving the correct output? Question: The challenge is given below: You will be given an array of numbers. You have to sort the odd numbers in ascending order while leaving the even numbers at their original positions. [7, 1] => [1, 7] [5, 8, 6, 3, 4] => …

Total answers: 5

How to test linear independence of binary array in python?

How to test linear independence of binary array in python? Question: The rows of this matrix are not linearly independent, as the first two rows can be added to produce the third: matrix = [ [ 1, 0, 0, 1 ], [ 0, 0, 1, 0 ], [ 1, 0, 1, 1 ], [ 1, …

Total answers: 2

Binary search always returning number not found

Binary search always returning number not found Question: I’m trying to code this binary search algorithm but it is always returning -1 and the value is never found. What am i doing wrong? Thank you! peso = [1,4,6,7,34,323,4333] userInput = int(input("Ingresa peso a ver si esta ingresado")) def binary_search(userInput): print(userInput) izq = 0 der = …

Total answers: 1

List iteration optimization

List iteration optimization Question: I’m trying to create a function to find the longest segment within a given list t, which satisfies two conditions: The last number of the segment has to be equal or greater than the first number of the segment. Difference between the last number and the first number of the segment …

Total answers: 1

Filter data frame based on absolute difference

Filter data frame based on absolute difference Question: I have the following data frame: import pandas as pd d1 = {‘id’: ["car", "car", "car", "plane", "plane", "car"], ‘value’: [1, 1.2, 5, 6, 1.3, 0.8]} df1 = pd.DataFrame(data=d1) df1 id value 0 car 1.0 1 car 1.2 2 car 5.0 3 plane 6.0 4 plane 1.3 …

Total answers: 3

AI algorithm for adjust percentages and constant coefficients values

AI algorithm for adjust percentages and constant coefficients values Question: I’m making an application that will help the people to donate stuff in one delivery point and then the application will determine who suits the item donated perfectly (the beneficiaries who receive the donations are inserted in the database previously) I’m making an algorithm to …

Total answers: 1

Checking if set of elements can jointly create parent element

Checking if set of elements can jointly create parent element Question: I have a dictionary with all elements and their children. For example, looking at the python dictionary below: product_dict = { ‘A’: {‘B’, ‘C’, ‘D’}, ‘B’: {‘E’, ‘F’}, ‘C’: {‘G’}, ‘D’: {}, ‘E’: {‘H’, ‘I’} } By the dict we can infer that, for …

Total answers: 1

Implementing of an inexact (approximate) Newton algorithm in Python using conjugate gradient

Implementing of an inexact (approximate) Newton algorithm in Python using conjugate gradient Question: I want to implement in Python an inexact (approximate) Newton algorithm given by pseudocode: Data: We have an x_0 in R^n and we let a function f:R^n->R, with positive hessian, 0<c1<1, 0<rho<1 The result: the result is to estimate the global minimum …

Total answers: 1