Skip to content

100 narray exercises

Kozo Nishida edited this page Jun 4, 2016 · 40 revisions

This is narray version of 100 numpy exercises

  1. Import the narray gem

    require "numo/narray"
  2. Create a null vector of size 10

    p Numo::Int32.zeros(10)
    p Numo::Float32.zeros(10)
  3. Create a null vector of size 10 but the fifth value which is 1

    Z = Numo::Int32.zeros(10)
    Z[4] = 1
    p Z
  4. Create a vector with values ranging from 10 to 49

    Z = Numo::Int32[10..49]
    p Z
  5. Reverse a vector (first element becomes last)

    Z = Numo::Int32[0..49]
    p Z.reverse
  6. Create a 3x3 matrix with values ranging from 0 to 8

    Z = Numo::Int32[0..8].reshape(3,3)
    p Z
Clone this wiki locally