Hello Pythonistas!
I'm looking for a way to duplicate entries in a symmetrical matrix
that's composed of genetic distances. For example, suppose I have a
matrix like the following:
A B C
A 0.000000 0.500000 1.000000
B 0.500000 0.000000 0.500000
C 1.000000 0.500000 0.000000
Say I want to duplicate entry B; the resulting matrix would look like:
A B B C
A 0.000000 0.500000 0.500000 1.000000
B 0.500000 0.000000 0.000000 0.500000
B 0.500000 0.000000 0.000000 0.500000
C 1.000000 0.500000 0.500000 0.000000
The cases I'd like to do this for are more complicated, naturally,
where I want to duplicate different entries different numbers of times.
I'm aware of Numeric, Numarray, and NumPy, though I've not used any of
them, but I am not sure if any of them possess a simple means to
duplicate entries in a matrix. I started writing code on my own but I
can see it is becoming exponentially more complex, and before I proceed
any further, I want to make sure I'm not reinventing any wheels. If
anyone here has any advice on how to manipulate matrices in this
manner, I'd _greatly_ appreciate it!
Thanks in advance,
Chris 5 2225
Chris Lasher wrote: Hello Pythonistas! I'm looking for a way to duplicate entries in a symmetrical matrix that's composed of genetic distances. For example, suppose I have a matrix like the following:
A B C A 0.000000 0.500000 1.000000 B 0.500000 0.000000 0.500000 C 1.000000 0.500000 0.000000
Say I want to duplicate entry B; the resulting matrix would look like:
A B B C A 0.000000 0.500000 0.500000 1.000000 B 0.500000 0.000000 0.000000 0.500000 B 0.500000 0.000000 0.000000 0.500000 C 1.000000 0.500000 0.500000 0.000000
The cases I'd like to do this for are more complicated, naturally, where I want to duplicate different entries different numbers of times. I'm aware of Numeric, Numarray, and NumPy, though I've not used any of them, but I am not sure if any of them possess a simple means to duplicate entries in a matrix. I started writing code on my own but I can see it is becoming exponentially more complex, and before I proceed any further, I want to make sure I'm not reinventing any wheels. If anyone here has any advice on how to manipulate matrices in this manner, I'd _greatly_ appreciate it!
Thanks in advance, Chris
Chris
Very rusty at this sort of thing, but if you premultiply the first
matrix by:
1 0 0
0 1 0
0 1 0
0 0 1
and postmultiply the result by:
1 0 0 0
0 1 1 0
0 0 0 1
I think you get what you want. (If that helps).
Gerard
Hey Gerard,
Thanks for the suggestion! It took me a while to figure out how to get
this to work. Two things were important: I needed to use the
matrixmultiply( ) function, and the order of the two matrices being
multiplied is critcial. Here's how I got the example to work. from Numeric import * array1 = array([[0.000000, 0.500000, 1.000000],
.... [0.500000, 0.000000, 0.500000],
.... [1.000000, 0.500000, 0.000000]]) array1
array([[ 0. , 0.5, 1. ],
[ 0.5, 0. , 0.5],
[ 1. , 0.5, 0. ]]) premul = array([[1, 0, 0], [0, 1, 0], [0, 1, 0], [0, 0, 1]]) premul
array([[1, 0, 0],
[0, 1, 0],
[0, 1, 0],
[0, 0, 1]]) res1 = matrixmultiply( premul, array1) res1
array([[ 0. , 0.5, 1. ],
[ 0.5, 0. , 0.5],
[ 0.5, 0. , 0.5],
[ 1. , 0.5, 0. ]]) postmul = array([[1, 0, 0, 0], [0, 1, 1, 0], [0, 0, 0, 1]]) postmul
array([[1, 0, 0, 0],
[0, 1, 1, 0],
[0, 0, 0, 1]]) array2 = matrixmultiply( res1, postmul) array2
array([[ 0. , 0.5, 0.5, 1. ],
[ 0.5, 0. , 0. , 0.5],
[ 0.5, 0. , 0. , 0.5],
[ 1. , 0.5, 0.5, 0. ]])
Now I have to figure out how to expand this concept to more complex
cases, and how to generate appropriate pre- and post-multiply
matrices... Hmm...
Thanks so much for getting me started,
Chris
Chris Lasher wrote: Hello Pythonistas! I'm looking for a way to duplicate entries in a symmetrical matrix that's composed of genetic distances. For example, suppose I have a matrix like the following:
A B C A 0.000000 0.500000 1.000000 B 0.500000 0.000000 0.500000 C 1.000000 0.500000 0.000000
Say I want to duplicate entry B; the resulting matrix would look like:
A B B C A 0.000000 0.500000 0.500000 1.000000 B 0.500000 0.000000 0.000000 0.500000 B 0.500000 0.000000 0.000000 0.500000 C 1.000000 0.500000 0.500000 0.000000
In [1]: from numpy import *
In [2]: A = array([[0.0, 0.5, 1.0],
...: [0.5, 0.0, 0.5],
...: [1.0, 0.5, 0.0]])
In [3]: B = repeat(A, [1,2,1])
In [4]: B
Out[4]:
array([[ 0. , 0.5, 1. ],
[ 0.5, 0. , 0.5],
[ 0.5, 0. , 0.5],
[ 1. , 0.5, 0. ]])
In [5]: C = repeat(B, [1,2,1], axis=-1)
In [6]: C
Out[6]:
array([[ 0. , 0.5, 0.5, 1. ],
[ 0.5, 0. , 0. , 0.5],
[ 0.5, 0. , 0. , 0.5],
[ 1. , 0.5, 0.5, 0. ]])
--
Robert Kern ro*********@gma il.com
"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter
Now that's definitely what I'm looking for! Thanks!
By the way, was this line
In [5]: C = repeat(B, [1,2,1], axis=-1)
supposed to have a positive 1 value for axis? It works either way, I
see. Is it like a lookup, where an index of -1 returns the last value?
If that were true, I supposed the evaluation would be 1, and thus gives
the same result.
Thanks again, very much. You guys are super-helpful!
Chris Lasher wrote: Now that's definitely what I'm looking for! Thanks!
By the way, was this line
In [5]: C = repeat(B, [1,2,1], axis=-1)
supposed to have a positive 1 value for axis? It works either way, I see. Is it like a lookup, where an index of -1 returns the last value? If that were true, I supposed the evaluation would be 1, and thus gives the same result.
That is correct.
--
Robert Kern ro*********@gma il.com
"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Gary Lundquest |
last post by:
I have an application with MS Access 2000 as the front end and MySQL as the
back end. All was well until I upgraded the MySQL (Linux) server.
The Problem: I insert data into a cumulative table. Before when I did
this, and there were duplicate entries, the duplicate entries were rejected
and I got a return code with the number of affected rows (number added).
Now, I get a MyODBC error and the application stops when trying to add...
|
by: Gary Lundquest |
last post by:
It appears to me that MySQL version 4 returns an error messge when doing an
Insert that results in duplicate entries. Version 3 did NOT return an
error - it dropped the duplicate entries and ran to completion. Version 4
seems to STOP when it encounters a duplicate entry, so that the records
before the duplicate are inserted and the records after the duplicate are
not inserted.
3.22.27.1 - previous ver MySQL that did not return error...
|
by: marx |
last post by:
I have a bit of a problem and any help would be much appreciated.
Problem: I have two dropdown list boxes with same data(all data
driven).
These are used for two separate entries.
For every entry you cannot choose the same value twice.
For example, I cannot choose for entry 1 the same
value in both selection boxes (gqCategory1Entry1 and
gqCategory2Entry1)
|
by: andreas.maurer1971 |
last post by:
Hi all,
since a few years I use the following statement to find duplicate
entries in a table:
SELECT t1.id, t2.id,...
FROM table AS t1 INNER JOIN table AS t2
ON t1.field = t2.field
WHERE t1.id < t2.id
|
by: Manish |
last post by:
The topic is related to MySQL database.
Suppose a table "address" contains the following records
-------------------------------------------------------
| name | address | phone |
-------------------------------------------------------
| mr x | 8th lane | 124364 |
| mr x | 6th lane | 435783 |
| mrs x | 6th lane | 435783 |
| |
by: teser3 |
last post by:
I have my PHP inserting into Oracle 9i.
But how do I prevent duplicate record entries?
I only have 3 fields in the insert in the action page:
CODE
<?php
$c=OCILogon("scott", "tiger", "orcl");
if ( ! $c ) {
echo "Unable to connect: " . var_dump( OCIError() );
|
by: Phox |
last post by:
I'm learning Python, and as a small exercise I made for myself I'm writing a program to find the determinate of a 2x2 matrix. I'm running Python 2.5 on Windows Vista, here's my code.
#for loop test.
#Finding the determinate of a 2x2 matrix
matrix =
newelement = raw_input("Enter your first value: ")
matrix.append(newelement)
|
by: ramdil |
last post by:
Hi All
I have table and it have around 90000 records.Its primary key is autonumber field and it has also have date column and name, then some other columns
Now i have problem with the table,as my table contains duplicate entries for a particular date.How can i delete the duplicate entries from the table for that particular column,Now i am doing manually with name column as it will be unique for that date.Can any one help me giving the query...
|
by: php_mysql_beginer911 |
last post by:
Hi ..
i am trying to update a table where if field contents any duplictaed
entries than one of the field should be updated with random number
which is unique so i can make all entries unique
i searched a lot but couldn't find any solution which i could
understand easily .
is it very difficult in sql to update duplicate entries with new
unique random values?
table example
----------------------
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |