page95.html
来自「Data Structures And Algorithms With Obje」· HTML 代码 · 共 42 行
HTML
42 行
<HTML><HEAD><TITLE>Dense Matrices</TITLE></HEAD><BODY bgcolor="#FFFFFF"> <a href="../index.html" target="_top"><img src="../icons/usins.gif" alt="Logo" align=right></a><b>Data Structures and Algorithms with Object-Oriented Design Patterns in Python</b><br><A NAME="tex2html2304" HREF="page96.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html2302" HREF="page89.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html2296" HREF="page94.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html2306" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H2><A NAME="SECTION004260000000000000000">Dense Matrices</A></H2><P>The simplest way to implement a matrix is to use a multi-dimensionalarray with two dimensions as shown in Program <A HREF="page95.html#progdenseMatrixa"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>.The <tt>DenseMatrix</tt> class extends the <tt>Matrix</tt> classdiscussed in the preceding section.The <tt>DenseMatrix</tt> class adds a instance attribute called <tt>_array</tt>which is a multi-dimensional array.The <tt>__init__</tt> method of the <tt>DenseMatrix</tt> class takes two arguments, <IMG WIDTH=69 HEIGHT=7 ALIGN=BOTTOM ALT="tex2html_wrap_inline60541" SRC="img616.gif" > and <IMG WIDTH=65 HEIGHT=10 ALIGN=BOTTOM ALT="tex2html_wrap_inline60543" SRC="img617.gif" >,and constructs the corresponding <IMG WIDTH=42 HEIGHT=14 ALIGN=MIDDLE ALT="tex2html_wrap_inline60545" SRC="img618.gif" > multi-dimensional array.Clearly, the running time of the <tt>__init__</tt> method is <I>O</I>(<I>mn</I>).<P><P><A NAME="3307"> </A><A NAME="progdenseMatrixa"> </A> <IMG WIDTH=575 HEIGHT=256 ALIGN=BOTTOM ALT="program3221" SRC="img619.gif" ><BR><STRONG>Program:</STRONG> <tt>DenseMatrix</tt> class <tt>__init__</tt>, <tt>__getitem__</tt> and <tt>__setitem__</tt> methods.<BR><P><P>Program <A HREF="page95.html#progdenseMatrixa"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A> also defines the <tt>__getitem__</tt> and <tt>setitem</tt>methods for the <tt>DenseMatrix</tt> class.These methods each take an ordered pair, (<I>i</I>,<I>j</I>),as the index expression and use the pairas the index into the multi-dimensional array.Because the number of dimensions is fixed at two,the running time for each of these methods is <I>O</I>(1).<P><HR><A NAME="tex2html2304" HREF="page96.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html2302" HREF="page89.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html2296" HREF="page94.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html2306" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <P><ADDRESS><img src="../icons/bruno.gif" alt="Bruno" align=right><a href="../copyright.html">Copyright © 2003</a> by <a href="../signature.html">Bruno R. Preiss, P.Eng.</a> All rights reserved.</ADDRESS></BODY></HTML>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?