distance

Maximum sum of two elements in an array minus the distance between them

ⅰ亾dé卋堺 提交于 2021-02-19 23:19:17
问题 I am trying to find the maximum sum of two elements in an array minus the distance between them. Specifically I am trying to calculate max{ a[i]+a[j]-|i-j| } I am currently stuck. I have obviously considered the naive approach (O(n^2)). However ,I am pretty sure there is a better ,more efficient approach (O(nlogn)) or even O(n). Can someone please help me on how to approach the problem. I would be grateful if anyone threw some hints or a simple idea to have something to start from. Sorting

Maximum sum of two elements in an array minus the distance between them

ぐ巨炮叔叔 提交于 2021-02-19 23:09:14
问题 I am trying to find the maximum sum of two elements in an array minus the distance between them. Specifically I am trying to calculate max{ a[i]+a[j]-|i-j| } I am currently stuck. I have obviously considered the naive approach (O(n^2)). However ,I am pretty sure there is a better ,more efficient approach (O(nlogn)) or even O(n). Can someone please help me on how to approach the problem. I would be grateful if anyone threw some hints or a simple idea to have something to start from. Sorting

R error: “Error in check.data : Argument Should be Numeric”

微笑、不失礼 提交于 2021-02-17 05:14:45
问题 I am learning about the "kohonen" library for the R programming language. I created some artificial data to try some of the functions on. I tried using the "supersom()" function on only continuous (i.e type = as.numeric) data and everything works well. However, when I tried to run the "supersom()" function on both continuous and categorical (type = as.factor), I start to run into some errors ("Argument data should be numeric"). The "supersom()" function has an argument called "dist.fct"

Calculate nearest distance to certain points in python

微笑、不失礼 提交于 2021-02-11 14:16:19
问题 I have a dataset as shown below, each sample has x and y values and the corresponding result Sr. X Y Resut 1 2 12 Positive 2 4 3 positive .... Visualization Grid size is 12 * 8 How I can calculate the nearest distance for each sample from red points (positive ones)? Red = Positive, Blue = Negative Sr. X Y Result Nearest-distance-red 1 2 23 Positive ? 2 4 3 Negative ? .... dataset 回答1: Its a lot easier when there is sample data, make sure to include that next time. I generate random data

Clustering multivariate time series - question regarding distance matrix

放肆的年华 提交于 2021-02-11 13:36:49
问题 I am trying to cluster meteorological stations using R. Stations provide such data as temperature, wind speed, humidity and some more on hourly intervals. I can easily cluster univariate time series using tsclust library, but when I cluster multivariate series I get errors. I have data as a list so each list element is a matrix with time series data of one station (variables are columns and rows are different timestamp). If I run: tsclust(data, k = 2, distance = 'Euclidean', seed = 3247,

how to select some lines created by points based on their distances in python

纵饮孤独 提交于 2021-02-11 12:30:14
问题 I have some lines created by connecting points of a regular grid and want to pair the correct lines to create surfces. This is coordinates of my point array: coord=np.array([[0.,0.,2.], [0.,1.,3.], [0.,2.,2.], [1.,0.,1.], [1.,1.,3.],\ [1.,2.,1.], [2.,0.,1.], [2.,1.,1.], [3.,0.,1.], [4.,0.,1.]]) Then, I created lines by connecting points. My points are from a regular grid. So, I have two perpendicular sets of lines. I called them blue (vertical) and red (horizontal) lines. To do so: blue_line=

Efficient Way to Convert Vector of Distances to Distance Object in R (ideally without creating a full distance matrix)

微笑、不失礼 提交于 2021-02-10 23:42:54
问题 I have a vector of distances which I get from some other procedure and want to convert it to a dist object in the R language . Below I give an example how such a vector looks like : distVector is computed in the same way said other procedure computes the distance vector. Ideally, I would like to transform this vector into a distance matrix ( dist object) without wasting resources. I think I could just transform it to a matrix by copying it as upper triangular and lower triangular matrix,

Efficient Way to Convert Vector of Distances to Distance Object in R (ideally without creating a full distance matrix)

青春壹個敷衍的年華 提交于 2021-02-10 23:39:52
问题 I have a vector of distances which I get from some other procedure and want to convert it to a dist object in the R language . Below I give an example how such a vector looks like : distVector is computed in the same way said other procedure computes the distance vector. Ideally, I would like to transform this vector into a distance matrix ( dist object) without wasting resources. I think I could just transform it to a matrix by copying it as upper triangular and lower triangular matrix,

Removing points from list if distance between 2 points is below a certain threshold

时光总嘲笑我的痴心妄想 提交于 2021-02-10 15:58:21
问题 I have a list of points and I want to keep the points of the list only if the distance between them is greater than a certain threshold. So, starting from the first point, if the the distance between the first point and the second is less than the threshold then I would remove the second point then compute the distance between the first one and the third one. If this distance is less than the threshold, compare the first and fourth point. Else move to the distance between the third and fourth

Removing points from list if distance between 2 points is below a certain threshold

纵然是瞬间 提交于 2021-02-10 15:52:12
问题 I have a list of points and I want to keep the points of the list only if the distance between them is greater than a certain threshold. So, starting from the first point, if the the distance between the first point and the second is less than the threshold then I would remove the second point then compute the distance between the first one and the third one. If this distance is less than the threshold, compare the first and fourth point. Else move to the distance between the third and fourth