matrix

Find the largest values on a matrix in R

有些话、适合烂在心里 提交于 2021-02-10 03:06:44
问题 I am working on a matrix in R, 230 x 230 and I want to extract the 10 (or any other number than 1) max inputs on the matrix, both their position and value. The extra problem is that this is a similarity matrix, so I have 1s in the diagonal which of course I want to leave out of the max search. Any ideas or commands for that? 回答1: A neat way to do this in general is with the underused arrayInd function, which gives you row and column positions for plain jane vector positions. That's how which(

How to access two dimensional array in prolog and how to loop each element in it

隐身守侯 提交于 2021-02-09 18:54:56
问题 How to access two dimensional array in prolog and how to loop each element in it For example if i have a matrix Question 1 how do i create a two-dimensional list like this in prolog: 1 2 3 4 5 6 7 8 9 Question 2: How do i loop each element and make every element +1 becomes 2 3 4 5 6 7 8 9 10 Question 3 public Cell(int row, int col, int cost, int units) { this.cost = cost; this.units = units; this.row = row; this.col = col; } In the matrix every thing is a object like cell My assignment is to

How to access two dimensional array in prolog and how to loop each element in it

故事扮演 提交于 2021-02-09 18:50:48
问题 How to access two dimensional array in prolog and how to loop each element in it For example if i have a matrix Question 1 how do i create a two-dimensional list like this in prolog: 1 2 3 4 5 6 7 8 9 Question 2: How do i loop each element and make every element +1 becomes 2 3 4 5 6 7 8 9 10 Question 3 public Cell(int row, int col, int cost, int units) { this.cost = cost; this.units = units; this.row = row; this.col = col; } In the matrix every thing is a object like cell My assignment is to

Dynamically create matrix from numerical input in C++

冷暖自知 提交于 2021-02-09 09:34:09
问题 I have a console application where I am trying to create a binary matrix from a numerical input. If a want to create a 2x4 matrix I must do two inputs inputs, one for each row. The input (console) will then look like this: First input: 1101 second input: 0111 And then I want to create a matrix that will look like this: { 1,1,0,1 0,1,1,1 } When the user is typing 1101 in the console, the number should be splitted into its digits and each digit will be stored in different indexes in the columns

pandas - apply function to current row against all other rows

江枫思渺然 提交于 2021-02-08 14:26:28
问题 I am utilizing pandas to create a dataframe that appears as follows: ratings = pandas.DataFrame({ 'article_a':[1,1,0,0], 'article_b':[1,0,0,0], 'article_c':[1,0,0,0], 'article_d':[0,0,0,1], 'article_e':[0,0,0,1] },index=['Alice','Bob','Carol','Dave']) I would like to compute another matrix from this input one that will compare each row against all other rows. Let's assume for example the computation was a function to find the length of the intersection set, I'd like an output DataFrame with

Convert binary file to image

匆匆过客 提交于 2021-02-08 13:35:18
问题 I need to find a fast way to convert a binary file to an image. The binary file consist of a N N N matrix and I want to associate 0 to a color and 1 to a different color. I need to perform this operation to more then 1000 binary files. If possible I'd like to avoid using MatLab, is there any tool/software (for unix) that would help me? EDIT: This is exactly what I was looking for! On the bottom of the page it says: "TIP: To process many files, use a shell script to pass this URL and your

Add value to every “other” field ((i+j)%2==0) of numpy array

半世苍凉 提交于 2021-02-08 12:53:07
问题 I have an m -by- n numpy array, and I'd like to add 1.0 to all entries [i, j] when (i + j) % 2 == 0 , i.e., "to every other square". I could of course simply iterate over the fields import numpy as np a = np.random.rand(5, 4) for i in range(a.shape[0]): for j in range(a.shape[1]): if (i + j) % 2 == 0: a[i, j] += 1.0 but needless to say this is really slow. Any idea of how to improve on this? 回答1: You can easily do the operation in two steps, like import numpy as np a = np.zeros((5, 14)) #

Add value to every “other” field ((i+j)%2==0) of numpy array

99封情书 提交于 2021-02-08 12:53:06
问题 I have an m -by- n numpy array, and I'd like to add 1.0 to all entries [i, j] when (i + j) % 2 == 0 , i.e., "to every other square". I could of course simply iterate over the fields import numpy as np a = np.random.rand(5, 4) for i in range(a.shape[0]): for j in range(a.shape[1]): if (i + j) % 2 == 0: a[i, j] += 1.0 but needless to say this is really slow. Any idea of how to improve on this? 回答1: You can easily do the operation in two steps, like import numpy as np a = np.zeros((5, 14)) #

how do I get individual elements of functions in a list and put them in a matrix in R? [closed]

北城以北 提交于 2021-02-08 10:40:28
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 2 months ago . Improve this question Edit: Included a sample result I created functions like so: Ex1 = function(a,b,c) 1 * a + 2 * b + 3 * c + 4 Ex2 = function(a,b,c) Ex3 = function(a,b,c) etc.. and put them in a list: exList = list(Ex1,Ex2,Ex3,etc.) now I have to use a function to get the individual elements (

Is there a way to sum a matrix entry and it's reflection across a diagonal along a given axis in a numpy array?

好久不见. 提交于 2021-02-08 10:30:48
问题 Suppose A = np.array([[1,2,0,3,5,0,0],[5,6,7,0,9,5,10]]) (The actual data set in this case is a square matrix with a shifted diagonal of zeros) I want to create an np array V that sums the pairs reflected across the first zero in each row, in the order of their distance from the zero. i.e., V[0]=[(2+3),(1+5),0] V[1] =[(7+9),(6+5),(10+5)]... So V = ([5,6,0],[16,11,15]) I can accomplish this in a very rudimentary way by looping through each row and then adding each row to a shifted version of