matrix

Number of submatricies containing all zeros

对着背影说爱祢 提交于 2021-02-07 09:27:50
问题 Is there a way to find a number of rectangular submatrices containing all zeros with a complexity smaller than O(n^3), where n is the dimension of given matrix? 回答1: Here is a solution O(n² log n) . First, let's convert the main problem to something like this: For given histogram, find the number of submatrices containing all zeros. How to convert it ? For each position calculate the height of column that start on that position and contain only zeros. Example: 10010 01101 00111 12000 00001 ->

How to calculate a rotation matrix in n dimensions given the point to rotate, an angle of rotation and an axis of rotation (n-2 subspace)

泄露秘密 提交于 2021-02-07 07:17:35
问题 I would like to calculate an (nxn) rotation matrix in the n-dimensional space given the following: The point to rotate. An angle of rotation. An axis of rotation (an (n-2) subspace that passes through the origin given by (n-2) unit vectors that span the subspace). the final rotated point. I think that number 4 (the final rotated point) is redundant and it is possible to calculate the rotation matrix without it. But I have them all. Is there a matlab function that already implements it? I know

multiple numpy dot products without a loop

北战南征 提交于 2021-02-07 03:38:13
问题 Is it possible to compute several dot products without a loop? say you have the following: a = randn(100, 3, 3) b = randn(100, 3, 3) I want to get an array z of shape (100, 3, 3) such that for all i z[i, ...] == dot(a[i, ...], b[i, ...]) in other words, which verifies: for va, vb, vz in izip(a, b, z): assert (vq == dot(va, vb)).all() The straightforward solution would be: z = array([dot(va, vb) for va, vb in zip(a, b)]) which uses an implicit loop (list comprehension + array). Is there a more

multiple numpy dot products without a loop

ⅰ亾dé卋堺 提交于 2021-02-07 03:34:31
问题 Is it possible to compute several dot products without a loop? say you have the following: a = randn(100, 3, 3) b = randn(100, 3, 3) I want to get an array z of shape (100, 3, 3) such that for all i z[i, ...] == dot(a[i, ...], b[i, ...]) in other words, which verifies: for va, vb, vz in izip(a, b, z): assert (vq == dot(va, vb)).all() The straightforward solution would be: z = array([dot(va, vb) for va, vb in zip(a, b)]) which uses an implicit loop (list comprehension + array). Is there a more

Different hard threshold for each column

那年仲夏 提交于 2021-02-07 02:13:10
问题 I would like to hard threshold my matrix such that all values below a certain number are set to zero. However, I would like that threshold to vary by the column (i.e. each column has its own threshold). How can I do this in R? Here is the simple set up: set.seed(1) A <- matrix(runif(n = 12),nrow = 4) # [,1] [,2] [,3] #[1,] 0.2655087 0.2016819 0.62911404 #[2,] 0.3721239 0.8983897 0.06178627 #[3,] 0.5728534 0.9446753 0.20597457 #[4,] 0.9082078 0.6607978 0.17655675 threshholds <- c(0.3,1,0.5)

Different hard threshold for each column

家住魔仙堡 提交于 2021-02-07 02:06:56
问题 I would like to hard threshold my matrix such that all values below a certain number are set to zero. However, I would like that threshold to vary by the column (i.e. each column has its own threshold). How can I do this in R? Here is the simple set up: set.seed(1) A <- matrix(runif(n = 12),nrow = 4) # [,1] [,2] [,3] #[1,] 0.2655087 0.2016819 0.62911404 #[2,] 0.3721239 0.8983897 0.06178627 #[3,] 0.5728534 0.9446753 0.20597457 #[4,] 0.9082078 0.6607978 0.17655675 threshholds <- c(0.3,1,0.5)

Calculate weighted pairwise distance matrix in Python

白昼怎懂夜的黑 提交于 2021-02-06 20:01:48
问题 I am trying to find the fastest way to perform the following pairwise distance calculation in Python. I want to use the distances to rank a list_of_objects by their similarity. Each item in the list_of_objects is characterised by four measurements a, b, c, d, which are made on very different scales e.g.: object_1 = [0.2, 4.5, 198, 0.003] object_2 = [0.3, 2.0, 999, 0.001] object_3 = [0.1, 9.2, 321, 0.023] list_of_objects = [object_1, object_2, object_3] The aim is to get a pairwise distance

Calculate weighted pairwise distance matrix in Python

情到浓时终转凉″ 提交于 2021-02-06 20:01:18
问题 I am trying to find the fastest way to perform the following pairwise distance calculation in Python. I want to use the distances to rank a list_of_objects by their similarity. Each item in the list_of_objects is characterised by four measurements a, b, c, d, which are made on very different scales e.g.: object_1 = [0.2, 4.5, 198, 0.003] object_2 = [0.3, 2.0, 999, 0.001] object_3 = [0.1, 9.2, 321, 0.023] list_of_objects = [object_1, object_2, object_3] The aim is to get a pairwise distance

Calculate weighted pairwise distance matrix in Python

最后都变了- 提交于 2021-02-06 20:00:43
问题 I am trying to find the fastest way to perform the following pairwise distance calculation in Python. I want to use the distances to rank a list_of_objects by their similarity. Each item in the list_of_objects is characterised by four measurements a, b, c, d, which are made on very different scales e.g.: object_1 = [0.2, 4.5, 198, 0.003] object_2 = [0.3, 2.0, 999, 0.001] object_3 = [0.1, 9.2, 321, 0.023] list_of_objects = [object_1, object_2, object_3] The aim is to get a pairwise distance

Calculate weighted pairwise distance matrix in Python

梦想的初衷 提交于 2021-02-06 20:00:27
问题 I am trying to find the fastest way to perform the following pairwise distance calculation in Python. I want to use the distances to rank a list_of_objects by their similarity. Each item in the list_of_objects is characterised by four measurements a, b, c, d, which are made on very different scales e.g.: object_1 = [0.2, 4.5, 198, 0.003] object_2 = [0.3, 2.0, 999, 0.001] object_3 = [0.1, 9.2, 321, 0.023] list_of_objects = [object_1, object_2, object_3] The aim is to get a pairwise distance