それ NArray でできるよ

B9dd885e3ef94ac5e0bcfdf4800ba703?s=47 tmaeda
February 08, 2014

それ NArray でできるよ

B9dd885e3ef94ac5e0bcfdf4800ba703?s=128

tmaeda

February 08, 2014
Tweet

Transcript

  1. 2.
  2. 22.
  3. 23.

    /"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. 24.

    /"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ܕͷ ºͷ࣍ݩ ഑ྻΛ༻ҙͯ͠
  5. 25.

    /"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 ࢝·ΓͰɺ ͣͭ૿Ճ͢Δ਺Ͱ ຒΊΔ
  6. 26.

    /"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
  7. 27.

    /"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
  8. 28.

    /"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 ͦΕΛ߹ܭ
  9. 29.

    ·ͱΊΔͱʁ 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
  10. 30.

    /"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 ͪΌΜͱºͷܗ Ͱදࣔͯ͘͠ΕΔ
  11. 31.

    /"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ͳͲΛॻ ͘ඞཁ͸ͳ͍ɻ
  12. 37.

    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
  13. 38.

    /"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. 39.

    /"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
  15. 40.

    /"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 ͦΕΛ߹ܭ
  16. 41.

    ·ͱΊΔͱʁ 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
  17. 43.

    ൺ΂ͯΈ·͠ΐ͏ x࣠ํ޲΁ͷ߹ܭ y࣠ํ޲΁ͷ߹ܭ Array a[1].inject(:+) a.map{|row| row[0]}. inject(:+) NArray na[true,

    1].sum na[0, true].sum "SSBZͩͱɺྻͷ߹ܭͷͱ͖ͷίʔυͱશ͘ର শੑ͕ͳ্͍ʹɺগ͠௕ͯ͘Կ΍͍ͬͯΔͷ͔ Θ͔Γʹ͍͘Ͱ͢Ͷ
  18. 50.

    /"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 ]
  19. 51.

    /"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
  20. 52.

    /"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࣠ํ޲ʹ ߹ܭ
  21. 53.

    ͪͳΈʹ 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
  22. 54.

    ͪͳΈʹ 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࣠ํ޲ʹ߹ܭ͞Εͯ
  23. 55.

    ͪͳΈʹ 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࣠ํ޲ʹ߹ܭ͞Εͯ
  24. 56.

    ͪͳΈʹ 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ͩͱɺ શํ޲ʹ ߹ܭ͞Ε·͢
  25. 64.

    ͜Μͳײ͡    "ళ  #ళ  $ళ 

    உ  ঁ  ୅  ୅      ººͷදʢۭؒ
  26. 65.

    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Ͱදݱ͢Δͱʁ
  27. 66.

    na[0, 0, 0] => 1 na[0, 1, 0] => 4

    na[0, 0, 1] => 7 ஋Λऔಘͯ͠Έ·͠ΐ͏ "ళ உ ୅ "ళ ঁ ୅ "ళ உ ୅
  28. 67.

    ୅ͷ஋શ෦͸ʁ na[true, true, 0] => NArray.int(3,2): [ [ 1, 2,

    3 ], [ 4, 5, 6 ] ] na[true, true, 0].sum => 21 ళશ෦ ୅ ੑผશ෦
  29. 68.

    உੑͷ஋શ෦͸ʁ na[true, 0, true] => NArray.int(3,2): [ [ 1, 2,

    3 ], [ 7, 8, 9 ] ] na[true, 0, true].sum => 30 ళશ෦ ੈ୅શ෦ உੑ
  30. 70.

    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 ] ]