Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - How to rewrite the matrix in python? How to write the following code in python
How to rewrite the matrix in python? How to write the following code in python
Python usually uses a third-party library like numpy to do calculations, which improves efficiency, speed and memory usage. If you write like this.

Number of rows = 18

cols= 10

Matrix = []

For I in xrange(0, line):

matrix.append([])

For j in xrange(0, cols):

Matrix [i]. Add (0)

Matrix [5][6]=3344

If you use numpy, this is its strength. There are examples in the tutorial. Copy them.

& gt& gt& gt from numpy import *

& gt& gt& gta = arange( 15)。 Plastic surgery (3, 5)

& gt& gt& gta

Array ([[ 0, 1, 2, 3, 4],

[ 5, 6, 7, 8, 9],

[ 10, 1 1, 12, 13, 14]])

There is also a tutorial here: http://hyry.dip.jp:8000/pydoc/numpy_intro.html.