Stack Overflow » Algorithm
90 FOLLOWERS
Read the most recent 30 Algorithm posts from Stack Overflow. The world's largest online community for developers, helping write the script of the future by serving developers and all technologists.
Stack Overflow » Algorithm
2d ago
Input a positive integer N, followed by the matrix A represented as N*N elements consisting of 0s or 1s, entered row by row, which depicts a two-dimensional map. Next, input the starting row coordinate L1, starting column coordinate C1, and ending row coordinate L2, ending column coordinate C2. The objective is to find a path in matrix A from the starting coordinates to the ending coordinates that is both passable and has the shortest distance and minimum number of turns. Additionally, the number of turns in the found path must be less than 10
Best programming Using Java
3
0 0 0
0 0 0
1 0 0
0 ..read more
Stack Overflow » Algorithm
2d ago
I'm a freshmen in TJU, and the title is my innovation and entrepreneurship event. Can you tell me the general and quickest way to learn the relevant knowledge? The intention is to integrate the large model into our university's online judge website for teaching. The model is needed several functions: explain how the data structure is implemented, correct students' wrong codes and recommend some relevant problems.
I know a little about it. I think here are two available ways: Large model fine-tuning (Actually I only know the name) or make our own dataset to train a open source model. So I want ..read more
How to use the python programming language to display the specified two excel changes in a web page?
Stack Overflow » Algorithm
2d ago
How to use the python programming language to display the specified two Excel changes in a web page? Similar to this picture
import streamlit as st
import pandas as pd
# 创建页面布局
st.set_page_config(page_title="fgtest", layout="wide", page_icon="test_icon")
# 读取 Excel 表格数据
df1 = pd.read_excel(r"E:\panda_gf\ci\EffectTable1.xlsx")
df2 = pd.read_excel(r"E:\panda_gf\ci\EffectTable2.xlsx")
# 获取两个 DataFrame 的所有列名并取并集
all_columns = set(df1.columns).union(df2.columns)
# 将两个 DataFrame 对齐并用 None 填充缺失值
df1 = df1.reindex(columns=all_columns, fill_value=None)
df2 = df2.reindex(columns=all_columns, fill_ ..read more
Stack Overflow » Algorithm
2d ago
I tried to implement ICP algorithm with numpy but my best_fit_transform function is not working. The result is more far than the original.
My main icp algorithm:
def icp(src, dst, max_iterations=1000, tolerance=0.001):
prev_error = float('inf')
for i in range(max_iterations):
closest = closest_points(src, dst)
R, t = best_fit_transform(dst, closest)
dst = (R @ dst.T).T + t
current_error = np.mean(np.linalg.norm(closest - dst, axis=1))
if np.abs(prev_error - current_error) < tolerance:
break
prev_error = current_ ..read more
Stack Overflow » Algorithm
2d ago
I am using QDA to classify two groups in a dataset. When I apply the algorithm, it gives me an error with this message:
Error in qda.default(x, grouping, ...) : lack of rank in group 0
I expect the algorithm to work and give me a result ..read more
Stack Overflow » Algorithm
2d ago
I need to find the solution to transportation problem with transit limitations and below there is the code which works correctly.
However I don't know how to input these limitations in the code.
Lower bound:
1
2
1
2
1
2
1
1
1
3
0
1
2
1
1
2
1
3
1
2
Upper bound:
9
8
6
10
5
7
15
4
6
9
5
6
6
5
10
8
5
7
4
8
All your ideas will be appreciated. Thanks in advance.
import pandas as pd
import pulp
truck_capacity = 6
suppliers = pd.RangeIndex(name='supplier', stop=4)
consumers = pd.RangeIndex(name='consumer', stop=5)
supply = pd.Series(
name='supply ..read more
Stack Overflow » Algorithm
2d ago
I wrote this code in bash scripting and can't figure out what the error is. The terminal say: 15: [:Illegal number: 0+1
This is the code: #!/bin/bash min=999 max=0 n=0 num=0 promedio=0 i=0
echo "Ingrese n"
read n
while [$i -le $n] ---> LINE 15 IN THE ACTUAL SCRIPT, HERE IS THE ERROR I CANT FIND
do
echo "Ingrese numero"
read num
if [$num -lt $min]
then
min=$num
fi
if [$num -gt $max]
then
max=$num
fi
promedio=$promedio+$num
i=$i+1
done
media=$promedio/$n
echo "Mayor: $max"
echo "Menor: $min"
echo "Promedio: $media"
I tried many things but as I'm not an expert and ..read more
Stack Overflow » Algorithm
2d ago
I'm looking at the "median of two arrays" in leetcode https://leetcode.com/problems/median-of-two-sorted-arrays/description/
I'm wondering, in the binary-search version solution, the red-circled part, why do we wanna make sure the nums1 is the smaller array? enter image description here
Some materials said it's for avoiding the overadjustment, but wouldn't focusing on smaller array also have this concern. Also, even if the overadjustment happens, it seems we can still reach the correct median after iterations ..read more
Stack Overflow » Algorithm
2d ago
So I have data.frame, with two columns of related indexes where every row refers to matching pair:
df <- data.frame(i=c(1,1,1,1,2,2,2,5), j=c(2,3,5,6,3,4,6,6))
# > df
| i | j |
------------
| 1 | 2 |
| 1 | 3 |
| 1 | 5 |
| 1 | 6 |
| 2 | 3 |
| 2 | 4 |
| 2 | 6 |
| 5 | 6 |
And I would like to group these pairs into larger blocks, where every element matches every other element, so for this df it would be:
block1: 1,2,3
block2: 1,5,6
block3: 2,4
block4: 2,6
block5: 5,6
For the clarification:
In block1 there is a relation between: 1 & 2, 1 & ..read more
Stack Overflow » Algorithm
2d ago
I have a modified library of DBSCAN to cluster points based on time and distance. Now can I add one more parameters such as TAXI-ID to cluster points based on this ID ? For example I want clusters where only 2 or more different Taxi-ID is present and remove clusters where the same ID is present throughout. I know the DBSCAN or clustering works based on the distance between these points but now I want these distances based on ID. Thank you
Example data would be
ID
Lat in m
Lon in m
Time(s)
1
23.6
85.69
236
2
29.6
84.69
238
1
23.6
86.69
245
import numpy as np
from scipy.spatial ..read more