Solved

matrix elements counting

Posted on 2011-03-17
1
394 Views
Last Modified: 2012-05-11
Hello,
I have the following matrix of 1s a,d 0s
5x6:                                   5x5
r1 1 1 0 0 1 1                     4 2 3 2 2
r2 1 0 0 0 1 0                     2 2 2 0 1
r3 1 0 1 0 1 1     =>            3 2 4 2 3  
r4 0 1 1 1 0 1                     2 0 2 4 3
r5 1 0 1 0 0 1                    2 1 3 3 3

What i want to do as un can see in the example is to compare:
1 with 1            2 with 1           etc.....
1 with 2            2 with 2
1 with 3           2 with  3
1 with 4           2 with  4
1 with 5          2 with  5

when i compre for example r1 with all the rows: If row === 1 i incremement the matrix(5x5) by 1 so M[1,1] = M[1,1] + 1
and see where all the element of row1 are 1 with the same elements in row2 are 1:
as u can see:
r1 1 1 0 0 1 1                    
r2 1 0 0 0 1 0    

row1 and row2 are only similar in 2 places the M[1,2] will be equal to 2 as u can see in the 5x5 matrix/          

Hope that it's clear, i'll explain it again if there is a problem.

Thank you so much      
0
Comment
Question by:dadadude
1 Comment
 

Accepted Solution

by:
dadadude earned 0 total points
ID: 35155460
I solved the problem on python:
But can u find an easier way?

for i in range(0,data.shape[0]):
		M1 = []
		for j in range(0,data.shape[1]):
			M1.append(data[i,j])
			
		for k in range(0,data.shape[0]):
			count = 0
			M2 = []
			for l in range(0,data.shape[1]):
				M2.append(data[k,l])
			
			for c in range(0,len(M1)):	
				if (M1[c] and M2[c] == 1.0):
					count = count + 1
			
			count = count + 1
			distance[i,k] = count

Open in new window

0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Strings in Python are the set of characters that, once defined, cannot be changed by any other method like replace. Even if we use the replace method it still does not modify the original string that we use, but just copies the string and then modif…
Flask is a microframework for Python based on Werkzeug and Jinja 2. This requires you to have a good understanding of Python 2.7. Lets install Flask! To install Flask you can use a python repository for libraries tool called pip. Download this f…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now