matrix

Filter 2D array and return co-ordinates from intermediate

你。 提交于 2020-05-15 02:26:35
问题 I have a 2D array of zeros with some positive integers at (1,6) and (2,7): [[0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.] [0. 0. 0. 0. 0. 0. 2. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.] [0. 0. 0. 0. 0. 0. 0. 2. 0. 0. 0. 0. 0. 0. 0. 0. 0.] [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]] And I want to filter the array by a custom kernel: [[1 0 1] [0 1 0] [0 1 0]] I want to filter the array with this kernel and when 2 or 3 of the ones in this kernel are multiplied by a positive integer, I want

Create clusters using correlation matrix in Python

蓝咒 提交于 2020-05-14 20:30:31
问题 all, I have a correlation matrix of 21 industry sectors. Now I want to split these 21 sectors into 4 or 5 groups, with sectors of similar behaviors grouped together. Can experts shed me some lights on how to do this in Python please? Thanks much in advance! 回答1: You might explore the use of Pandas DataFrame.corr and the scipy.cluster Hierarchical Clustering package import pandas as pd import scipy.cluster.hierarchy as spc df = pd.DataFrame(my_data) corr = df.corr().values pdist = spc.distance

Create clusters using correlation matrix in Python

一笑奈何 提交于 2020-05-14 20:27:05
问题 all, I have a correlation matrix of 21 industry sectors. Now I want to split these 21 sectors into 4 or 5 groups, with sectors of similar behaviors grouped together. Can experts shed me some lights on how to do this in Python please? Thanks much in advance! 回答1: You might explore the use of Pandas DataFrame.corr and the scipy.cluster Hierarchical Clustering package import pandas as pd import scipy.cluster.hierarchy as spc df = pd.DataFrame(my_data) corr = df.corr().values pdist = spc.distance

In R how to control multi-threading in BLAS parallel matrix product

瘦欲@ 提交于 2020-05-13 07:27:46
问题 I have a question regarding the use of BLAS parallelized matrix product in R (being the default matrix product at least since R-3.4, maybe earlier). The default behavior (at least on my machine) is now for the matrix product (c.f. example below) to use all the cores available on the machine, which can be a problem. Do you know how to control the number of cores used for standard matrix product in R? Thanks in advance Example: n=10000 p=1000 q=5000 A = matrix(runif(n*p),nrow=n, ncol=p) B =

C++: How to use unnamed template parameters in class members?

人走茶凉 提交于 2020-05-12 12:01:28
问题 I am creating a simple Matrix class. I am trying to add an unnamed template parameter to make sure it is used with integral types #include <string> #include <vector> #include <boost/utility/enable_if.hpp> #include <boost/type_traits/is_scalar.hpp> template <typename T, typename = typename boost::enable_if<boost::is_scalar<T> >::type> class Matrix { public: Matrix(const size_t nrow, const size_t ncol); private: const size_t nrow_; const size_t ncol_; std::vector<std::string> rownames_; std:

C++: How to use unnamed template parameters in class members?

怎甘沉沦 提交于 2020-05-12 12:01:06
问题 I am creating a simple Matrix class. I am trying to add an unnamed template parameter to make sure it is used with integral types #include <string> #include <vector> #include <boost/utility/enable_if.hpp> #include <boost/type_traits/is_scalar.hpp> template <typename T, typename = typename boost::enable_if<boost::is_scalar<T> >::type> class Matrix { public: Matrix(const size_t nrow, const size_t ncol); private: const size_t nrow_; const size_t ncol_; std::vector<std::string> rownames_; std:

How to change view's size from 4 side in Android?

一世执手 提交于 2020-05-07 19:15:41
问题 Is it possible to resize by pulling the matrix on the 4 side of the view? I can resize from a single point to a ratio like this. The example above works as follows: protected boolean onTouchDown(@NonNull MotionEvent event) { oldDistance = (float) Math.sqrt((midPoint.x-event.getX()) * (midPoint.x-event.getX()) + (midPoint.y-event.getY()) * (midPoint.y-event.getY())); ... } float newDistance = (float) Math.sqrt((midPoint.x-event.getX()) * (midPoint.x-event.getX()) + (midPoint.y-event.getY()) *

Given three nxn arrays, produce the output A+B=C where A, B and C are represented as matrices in the output using C programming language

耗尽温柔 提交于 2020-04-30 06:24:07
问题 Assume the matrices to be of the form, The required output on stdout using C language should be My code: #include<stdio.h> int main(void) { int size, i=0, j=0; printf("Enter the size of the array:"); scanf("%d",&size); int A[size][size], B[size][size], C[size][size]; //Entering the values in A[][] printf("enter the elements of Array A:\n"); for(int i=0; i<size; i++) for(int j=0; j<size; j++) scanf("%d",&A[i][j]); //Entering the values in B[][] printf("enter the elements of Array B:\n"); for

convert matrix to numeric data frame

最后都变了- 提交于 2020-04-29 09:52:12
问题 I have some data in a somewhat inconvenient format. It is saved as a matrix, with all column vectors being characters. datamatrix <- structure(c("1", "2", "3", "4", "0.9301", "0.93", "0.9286", "0.9209", "0.9", "0.8064", "0.7947", "0.7607", "0.8042", "0.7847", "0.7832", "0.7578", "0.7487", "0.7105", "0.6566", "0.5951", "0.6951", "0.677", "0.6588", "0.5922", "0.6889", "0.6471", "0.6524", "0.5932"), .Dim = c(4L, 7L)) My aim is to convert this matrix to a dataframe and the column vectors to the

convert matrix to numeric data frame

寵の児 提交于 2020-04-29 09:50:14
问题 I have some data in a somewhat inconvenient format. It is saved as a matrix, with all column vectors being characters. datamatrix <- structure(c("1", "2", "3", "4", "0.9301", "0.93", "0.9286", "0.9209", "0.9", "0.8064", "0.7947", "0.7607", "0.8042", "0.7847", "0.7832", "0.7578", "0.7487", "0.7105", "0.6566", "0.5951", "0.6951", "0.677", "0.6588", "0.5922", "0.6889", "0.6471", "0.6524", "0.5932"), .Dim = c(4L, 7L)) My aim is to convert this matrix to a dataframe and the column vectors to the