matrix

print numbers in ascending order from an n x m array whose rows are sorted

ε祈祈猫儿з 提交于 2020-01-14 13:56:49
问题 We have an n x m matrix whose rows are sorted, we need to print the numbers in the matrix in ascending order. The columns are not necessarly sorted. The solution that came to my mind was simple merging the rows in the matrix considering them as separate lists(basically the merging step in merge sort) which in merge sort takes O(n). I wanted to know what is the complexity of merging n separate arrays as in this case. I thought it would be O(n x m) but I am not sure. Also, what would be a

print numbers in ascending order from an n x m array whose rows are sorted

空扰寡人 提交于 2020-01-14 13:54:06
问题 We have an n x m matrix whose rows are sorted, we need to print the numbers in the matrix in ascending order. The columns are not necessarly sorted. The solution that came to my mind was simple merging the rows in the matrix considering them as separate lists(basically the merging step in merge sort) which in merge sort takes O(n). I wanted to know what is the complexity of merging n separate arrays as in this case. I thought it would be O(n x m) but I am not sure. Also, what would be a

Why is a.dot(b) faster than a@b although Numpy recommends a@b

混江龙づ霸主 提交于 2020-01-14 13:43:24
问题 According to the answers from this question and also according to numpy, matrix multiplication of 2-D arrays is best done via a @ b , or numpy.matmul(a,b) as compared to a.dot(b) . If both a and b are 2-D arrays, it is matrix multiplication, but using matmul or a @ b is preferred. I did the following benchmark and found contrary results. Questions: Is there an issue with my benchmark? If not, why does Numpy not recommend a.dot(b) when it is faster than a@b or numpy.matmul(a,b) ? Benchmark

Why is a.dot(b) faster than a@b although Numpy recommends a@b

大兔子大兔子 提交于 2020-01-14 13:42:27
问题 According to the answers from this question and also according to numpy, matrix multiplication of 2-D arrays is best done via a @ b , or numpy.matmul(a,b) as compared to a.dot(b) . If both a and b are 2-D arrays, it is matrix multiplication, but using matmul or a @ b is preferred. I did the following benchmark and found contrary results. Questions: Is there an issue with my benchmark? If not, why does Numpy not recommend a.dot(b) when it is faster than a@b or numpy.matmul(a,b) ? Benchmark

align 2 matrice for maximum overlap

心不动则不痛 提交于 2020-01-14 10:23:19
问题 So following is an interview problem. Given two N 2 matrices with entries being 0 or 1 . How can we find out the number of maximum overlapping 1 's possible? Note: You can only move the matrix upward, downward, leftward and rightward, so rotation is not allowed Currently I'm stuck at the most naive O(N^4) method, which being align the top left corner of one matrix to every possible position of the other matrix and count the all the overlap 1s. Example : [0 1 0] [0 0 1] A: [1 0 0] B: [0 0 1]

printing matrices and vectors side by side

﹥>﹥吖頭↗ 提交于 2020-01-14 09:52:08
问题 For tutorial purposes, I'd like to be able to print or display matrices and vectors side-by-side, often to illustrate the result of a matrix equation, like $A x = b$. I could do this using SAS/IML, where the print statement takes an arbitrary collection of (space separated) expressions, evaluates them and prints the result, e.g., print A ' * ' x '=' (A * x) '=' b; A X #TEM1001 B 1 1 -4 * 0.733 = 2 = 2 1 -2 1 -0.33 1 1 1 1 1 -0.4 0 0 Note that quoted strings are printed as is. I've searched,

Getting an error “number of items to replace is not a multiple of replacement length”

六月ゝ 毕业季﹏ 提交于 2020-01-14 07:52:21
问题 I'm trying to convert a record into a date and time format using the strptime function. However, I'm not sure why I'm getting the error: number of items to replace is not a multiple of replacement length. I tried to check the length of the record using the length function but both have the same length. data <- DT head(data[6]) # column # 1 2014-12-22 23:53:48 # 2 2014-12-22 23:20:34 # 3 2014-12-22 23:20:30 # 4 2014-12-22 23:20:16 # 5 2014-12-22 23:20:07 # 6 2014-12-22 23:05:49 data[,6] <- as

constructing a square matrix of edge N, and its element should not be same across same row and column

江枫思渺然 提交于 2020-01-14 07:07:44
问题 So, I was constructing a matrix (square) of length N, its element i should between 1 <= i < 2 * N Each element should be between 1 to 2 * N - 1 for each i and j (1 <= i <= N and 1 <= j < 2 * N ) the j element should appear in i th row / i column for any N if the desired matrix is not possible we have print -1; Which means for N = 2 We could get matrix as - 1 2 3 1 As we can see for 1st row and column we can get 1 , 2 , 3. and for 2nd row and column we get 1, 2, 3 Another example : for N = 4 1

Effificient distance-like matrix computation (manual metric function)

倖福魔咒の 提交于 2020-01-14 05:55:08
问题 I want to compute a "distance" matrix, similarly to scipy.spatial.distance.cdist, but using the intersection over union (IoU) between "bounding boxes" (4-dimensional vectors), instead of a typical distance metric (like the Euclidean distance). For example, let's suppose that we have two collections of bounding boxes, such as import numpy as np A_bboxes = np.array([[0, 0, 10, 10], [5, 5, 15, 15]]) array([[ 0, 0, 10, 10], [ 5, 5, 15, 15]]) B_bboxes = np.array([[1, 1, 11, 11], [4, 4, 13, 13], [9

Effificient distance-like matrix computation (manual metric function)

帅比萌擦擦* 提交于 2020-01-14 05:54:05
问题 I want to compute a "distance" matrix, similarly to scipy.spatial.distance.cdist, but using the intersection over union (IoU) between "bounding boxes" (4-dimensional vectors), instead of a typical distance metric (like the Euclidean distance). For example, let's suppose that we have two collections of bounding boxes, such as import numpy as np A_bboxes = np.array([[0, 0, 10, 10], [5, 5, 15, 15]]) array([[ 0, 0, 10, 10], [ 5, 5, 15, 15]]) B_bboxes = np.array([[1, 1, 11, 11], [4, 4, 13, 13], [9