From: Paul Duncan Date: 2007-02-14T03:05:07+09:00 Subject: Re: Extracting sub elements in array --rJwd6BRFiFCcLxzm Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable * WKC CCC (wai-kee.chung@uk.bnpparibas.com) wrote: > Is there a fast way to return a subsection of an array object as there > is the minor function for a Matrix? >=20 > For example > testArray =3D [[1,2,3,4,5], > [7,8,9,10,11]] >=20 > How can the elements [[4,5],[10,11]] be extracted? Use the built-in matrix class: require 'matrix' m =3D Matrix.rows (1..5).to_a, (7..11).to_a # extract the subsection at rows 0..1 and cols 3..4 m.minor(0..1, 3..4) #=3D> Matrix[[4, 5], [10, 11]] See the matrix documentation for additional documentation: =20 http://ruby-doc.org/stdlib/libdoc/matrix/rdoc/index.html --=20 Paul Duncan pabs in #ruby-lang (OPN IRC) http://www.pablotron.org/ OpenPGP Key ID: 0x82C29562 --rJwd6BRFiFCcLxzm Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) iD8DBQFF0f3PzdlT34LClWIRAi1dAJ9oThOpiWNd3je+zOXPzSVGF9TxpwCgwcX5 lu/vhbolh/ydwKCN4m/1JqI= =7b1W -----END PGP SIGNATURE----- --rJwd6BRFiFCcLxzm--