-
Notifications
You must be signed in to change notification settings - Fork 42
100 narray exercises
Kozo Nishida edited this page Jun 4, 2016
·
40 revisions
This is narray version of 100 numpy exercises
-
Import the narray gem
require "numo/narray"
-
Create a null vector of size 10
p Numo::Int32.zeros(10) p Numo::Float32.zeros(10)
-
Create a null vector of size 10 but the fifth value which is 1
Z = Numo::Int32.zeros(10) Z[4] = 1 p Z
-
Create a vector with values ranging from 10 to 49
Z = Numo::Int32[10..49] p Z
-
Reverse a vector (first element becomes last)
Z = Numo::Int32[0..49] p Z.reverse
-
Create a 3x3 matrix with values ranging from 0 to 8
Z = Numo::Int32[0..8].reshape(3,3) p Z
-
Find indices of non-zero elements from [1,2,0,0,4,0]
-
Create a 3x3 identity matrix