Upgrade to Pro — share decks privately, control downloads, hide ads and more …

それ NArray でできるよ

tmaeda
February 08, 2014

それ NArray でできるよ

tmaeda

February 08, 2014
Tweet

More Decks by tmaeda

Other Decks in Technology

Transcript

  1. /"SSBZͩͱʁ na = NArray.int(3,3).indgen!(1,1) => NArray.int(3,3): [ [ 1, 2,

    3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] na[true, 1] => NArray.int(3): [ 4, 5, 6 ] na[true, 1].sum => 15
  2. /"SSBZͩͱʁ na = NArray.int(3,3).indgen!(1,1) => NArray.int(3,3): [ [ 1, 2,

    3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] na[true, 1] => NArray.int(3): [ 4, 5, 6 ] na[true, 1].sum => 15 JOUܕͷ ºͷ࣍ݩ ഑ྻΛ༻ҙͯ͠
  3. /"SSBZͩͱʁ na = NArray.int(3,3).indgen!(1,1) => NArray.int(3,3): [ [ 1, 2,

    3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] na[true, 1] => NArray.int(3): [ 4, 5, 6 ] na[true, 1].sum => 15 ࢝·ΓͰɺ ͣͭ૿Ճ͢Δ਺Ͱ ຒΊΔ
  4. /"SSBZͩͱʁ na = NArray.int(3,3).indgen!(1,1) => NArray.int(3,3): [ [ 1, 2,

    3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] na[true, 1] => NArray.int(3): [ 4, 5, 6 ] na[true, 1].sum => 15 ศ্ٓɺԣ࣠ΛY࣠ɺ ॎ࣠ΛZ࣠ͱݺͼ·͢ Αɻ Y Z
  5. /"SSBZͩͱʁ na = NArray.int(3,3).indgen!(1,1) => NArray.int(3,3): [ [ 1, 2,

    3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] na[true, 1] => NArray.int(3): [ 4, 5, 6 ] na[true, 1].sum => 15 Y࣠͸શ෦ɺ Z࣠͸൪໨ɺ Λऔಘ ศ্ٓɺԣ࣠ΛY࣠ɺ ॎ࣠ΛZ࣠ͱݺͼ·͢ Αɻ Y Z
  6. /"SSBZͩͱʁ na = NArray.int(3,3).indgen!(1,1) => NArray.int(3,3): [ [ 1, 2,

    3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] na[true, 1] => NArray.int(3): [ 4, 5, 6 ] na[true, 1].sum => 15 ͦΕΛ߹ܭ
  7. ·ͱΊΔͱʁ na = NArray.int(3,3).indgen!(1,1) => NArray.int(3,3): [ [ 1, 2,

    3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] na[true, 1].sum => 15
  8. /"SSBZͷಛ௕ na = NArray.int(3,3).indgen!(1,1) => NArray.int(3,3): [ [ 1, 2,

    3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] na[true, 1].sum => 15 ͪΌΜͱºͷܗ Ͱදࣔͯ͘͠ΕΔ
  9. /"SSBZͷಛ௕ na = NArray.int(3,3).indgen!(1,1) => NArray.int(3,3): [ [ 1, 2,

    3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] na[true, 1].sum => 15 ૢ࡞͸શͯNBQɻ ࣗ෼ͰNBQ ΍JOKFDUͳͲΛॻ ͘ඞཁ͸ͳ͍ɻ
  10. 3VCZඪ४ͷ"SSBZͩͱʁ a = [[1,2,3], [4,5,6], [7,8,9]] => [[1, 2, 3],

    [4, 5, 6], [7, 8, 9]] a.map{|row| row[0]}.inject(:+) => 12
  11. /"SSBZͩͱʁ na = NArray.int(3,3).indgen!(1,1) => NArray.int(3,3): [ [ 1, 2,

    3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] na[0, true] => NArray.int(3): [ 1, 4, 7 ] na[0, true].sum => 12
  12. /"SSBZͩͱʁ na = NArray.int(3,3).indgen!(1,1) => NArray.int(3,3): [ [ 1, 2,

    3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] na[0, true] => NArray.int(3): [ 1, 4, 7 ] na[0, true].sum => 12 Y࣠͸൪໨ɺ Z࣠͸શ෦ Λऔಘ Y Z
  13. /"SSBZͩͱʁ na = NArray.int(3,3).indgen!(1,1) => NArray.int(3,3): [ [ 1, 2,

    3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] na[0, true] => NArray.int(3): [ 1, 4, 7 ] na[0, true].sum => 12 ͦΕΛ߹ܭ
  14. ·ͱΊΔͱʁ na = NArray.int(3,3).indgen!(1,1) => NArray.int(3,3): [ [ 1, 2,

    3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] na[0, true].sum => 12
  15. ൺ΂ͯΈ·͠ΐ͏ x࣠ํ޲΁ͷ߹ܭ y࣠ํ޲΁ͷ߹ܭ Array a[1].inject(:+) a.map{|row| row[0]}. inject(:+) NArray na[true,

    1].sum na[0, true].sum "SSBZͩͱɺྻͷ߹ܭͷͱ͖ͷίʔυͱશ͘ର শੑ͕ͳ্͍ʹɺগ͠௕ͯ͘Կ΍͍ͬͯΔͷ͔ Θ͔Γʹ͍͘Ͱ͢Ͷ
  16. /"SSBZͰ na = NArray.int(3,3).indgen!(1,1) => NArray.int(3,3): [ [ 1, 2,

    3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] na[true, [0,1]] => NArray.int(3,2): [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] na[true, [0,1]].sum(1) => NArray.int(3): [ 5, 7, 9 ]
  17. /"SSBZͰ na = NArray.int(3,3).indgen!(1,1) => NArray.int(3,3): [ [ 1, 2,

    3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] na[true, [0,1]] => NArray.int(3,2): [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] na[true, [0,1]].sum(1) => NArray.int(3): [ 5, 7, 9 ] Y࣠͸શ෦ɺ Z࣠͸൪໨ͱ൪໨ Λऔಘ Y Z
  18. /"SSBZͰ na = NArray.int(3,3).indgen!(1,1) => NArray.int(3,3): [ [ 1, 2,

    3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] na[true, [0,1]] => NArray.int(3,2): [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] na[true, [0,1]].sum(1) => NArray.int(3): [ 5, 7, 9 ] ͦΕΛZ࣠ํ޲ʹ ߹ܭ
  19. ͪͳΈʹ na[true, [0,1]] => NArray.int(3,2): [ [ 1, 2, 3

    ], [ 4, 5, 6 ] ] na[true, [0,1]].sum(0) na[true, [0,1]].sum(1) na[true, [0,1]].sum => NArray.int(2): [ 6, 15 ] => NArray.int(3): [ 5, 7, 9 ] => 21
  20. ͪͳΈʹ na[true, [0,1]] => NArray.int(3,2): [ [ 1, 2, 3

    ], [ 4, 5, 6 ] ] na[true, [0,1]].sum(0) na[true, [0,1]].sum(1) na[true, [0,1]].sum => NArray.int(2): [ 6, 15 ] => NArray.int(3): [ 5, 7, 9 ] => 21 TVN  ͩͱɺ Y࣠ํ޲ʹ߹ܭ͞Εͯ
  21. ͪͳΈʹ na[true, [0,1]] => NArray.int(3,2): [ [ 1, 2, 3

    ], [ 4, 5, 6 ] ] na[true, [0,1]].sum(0) na[true, [0,1]].sum(1) na[true, [0,1]].sum => NArray.int(2): [ 6, 15 ] => NArray.int(3): [ 5, 7, 9 ] => 21 TVN  ͩͱɺ Z࣠ํ޲ʹ߹ܭ͞Εͯ
  22. ͪͳΈʹ na[true, [0,1]] => NArray.int(3,2): [ [ 1, 2, 3

    ], [ 4, 5, 6 ] ] na[true, [0,1]].sum(0) na[true, [0,1]].sum(1) na[true, [0,1]].sum => NArray.int(2): [ 6, 15 ] => NArray.int(3): [ 5, 7, 9 ] => 21 TVNͩͱɺ શํ޲ʹ ߹ܭ͞Ε·͢
  23. ͜Μͳײ͡    "ళ  #ళ  $ళ 

    உ  ঁ  ୅  ୅      ººͷදʢۭؒ
  24. na = NArray.int(3, 2, 2).indgen!(1, 1) => NArray.int(3,2,2): [ [

    [ 1, 2, 3 ], [ 4, 5, 6 ] ], [ [ 7, 8, 9 ], [ 10, 11, 12 ] ] ] /"SSBZͰදݱ͢Δͱʁ
  25. na[0, 0, 0] => 1 na[0, 1, 0] => 4

    na[0, 0, 1] => 7 ஋Λऔಘͯ͠Έ·͠ΐ͏ "ళ உ ୅ "ళ ঁ ୅ "ళ உ ୅
  26. ୅ͷ஋શ෦͸ʁ na[true, true, 0] => NArray.int(3,2): [ [ 1, 2,

    3 ], [ 4, 5, 6 ] ] na[true, true, 0].sum => 21 ళશ෦ ୅ ੑผશ෦
  27. உੑͷ஋શ෦͸ʁ na[true, 0, true] => NArray.int(3,2): [ [ 1, 2,

    3 ], [ 7, 8, 9 ] ] na[true, 0, true].sum => 30 ళશ෦ ੈ୅શ෦ உੑ
  28. cube = Cube.new([ {key: :mise, values: ["Aళ", "Bళ", "Cళ"]}, {key:

    :sedai, values: ["10୅","20୅"]}, {key: :sei, values:["உ","ঁ"]} ]) # ళA, 20୅, ঁʹ20Λઃఆ cube.set( { mise: "Aళ", sedai: "20୅", sei: "ঁ" }, 20) # ళA, 20୅, ঁͷ஋Λऔಘ cube.get( { mise: "Aళ", sedai: "20୅", sei: "ঁ" }) => 20 # 10୅ͷ஋Λऔಘ cube.get( { sedai: "10୅"} ) => NArray.int(3,2): [ [ 1, 2, 3 ], [ 7, 8, 9 ] ]