--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?
> 
> For example
>  testArray = [[1,2,3,4,5],
>               [7,8,9,10,11]]
> 
> How can the elements [[4,5],[10,11]] be extracted?

Use the built-in matrix class:

  require 'matrix'

  m = 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) #=> Matrix[[4, 5], [10, 11]]

See the matrix documentation for additional documentation:
  
  http://ruby-doc.org/stdlib/libdoc/matrix/rdoc/index.html

-- 
Paul Duncan <pabs / pablotron.org>        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{1W
-----END PGP SIGNATURE-----

--rJwd6BRFiFCcLxzm--