Skip to content

Commit f0c2aaf

Browse files
pvalle6peterjc
authored andcommitted
Update Phylo_cookbook.md
Updating Numpy references to documentation recommended. biopython/biopython#4238 (comment) Licensed under Biopython License Agreement and 3-Clause BSD License
1 parent 53c73d6 commit f0c2aaf

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

wiki/Phylo_cookbook.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ bptree = Phylo.read("tmp.nwk", "newick")
309309
exists, otherwise 0 (false).
310310

311311
``` python
312-
import numpy
312+
import numpy as np
313313

314314

315315
def to_adjacency_matrix(tree):
@@ -327,21 +327,21 @@ def to_adjacency_matrix(tree):
327327
lookup = {}
328328
for i, elem in enumerate(allclades):
329329
lookup[elem] = i
330-
adjmat = numpy.zeros((len(allclades), len(allclades)))
330+
adjmat = np.zeros((len(allclades), len(allclades)))
331331
for parent in tree.find_clades(terminal=False, order="level"):
332332
for child in parent.clades:
333333
adjmat[lookup[parent], lookup[child]] = 1
334334
if not tree.rooted:
335335
# Branches can go from "child" to "parent" in unrooted trees
336336
adjmat = adjmat + adjmat.transpose()
337-
return (allclades, numpy.matrix(adjmat))
337+
return (allclades, np.matrix(adjmat))
338338
```
339339

340340
**Distance matrix:** cell values are branch lengths if a branch exists,
341341
otherwise infinity (this plays well with graph algorithms).
342342

343343
``` python
344-
import numpy
344+
import numpy as np
345345

346346

347347
def to_distance_matrix(tree):
@@ -357,15 +357,15 @@ def to_distance_matrix(tree):
357357
lookup = {}
358358
for i, elem in enumerate(allclades):
359359
lookup[elem] = i
360-
distmat = numpy.repeat(numpy.inf, len(allclades) ** 2)
360+
distmat = np.repeat(np.inf, len(allclades) ** 2)
361361
distmat.shape = (len(allclades), len(allclades))
362362
for parent in tree.find_clades(terminal=False, order="level"):
363363
for child in parent.clades:
364364
if child.branch_length:
365365
distmat[lookup[parent], lookup[child]] = child.branch_length
366366
if not tree.rooted:
367367
distmat += distmat.transpose
368-
return (allclades, numpy.matrix(distmat))
368+
return (allclades, np.matrix(distmat))
369369
```
370370

371371
Enhancements:

0 commit comments

Comments
 (0)