နည်းပါးသည် သုတေသန အရွက်

ပရိုဂရမ်ပညာ

ကျမ်းဆိုင်းများ

အုပ်စု အကိရိယာ ဖတ်ရှုရန်

အုပ်စု အရည်အချင်း အသုံးစွဲမှု အုပ်စု အကိရိယာ ဖတ်ရှုခြင်း နှင့် အတူတူပါသည်。

Example

အရည်အချင်း အမှတ် ကို ကိုယ်စားပြု၍ အုပ်စု အကိရိယာ ကို ဖတ်ရှုနိုင်ပါသည်。

import numpy as np
arr = np.array([1, 2, 3, 4])
NumPy အုပ်စု တွင် အရည်အချင်း အသုံးစွဲမှု 0 မှ စတင်၍ ပထမ အကိရိယာ အရည်အချင်း အမှတ် 0 ဖြစ်၍ 2-မြောက် အကိရိယာ အရည်အချင်း အမှတ် 1 ဖြစ်ပြီး ထို့နောက် ပြောင်းလဲသည်。

လုပ်ကျင်ခြင်း

Example

ဒီ အုပ်စု မှ 1-မြောက် အကိရိယာ ကို ဖတ်ရှုရန်

import numpy as np
arr = np.array([1, 2, 3, 4])
ဒီ အုပ်စု မှ 2-မြောက် အကိရိယာ ကို ဖတ်ရှုရန်

လုပ်ကျင်ခြင်း

Example

ဒီ အုပ်စု မှ 3-မြောက် နှင့် 4-မြောက် အကိရိယာ ကို နှိပ်တွဲ၍ ပြန်လည်ထုတ်ပြန်ခြင်း

import numpy as np
arr = np.array([1, 2, 3, 4])
print(arr[2] + arr[3])

လုပ်ကျင်ခြင်း

2-D အုပ်စု ကို ဖတ်ရှုရန်

ဒီ 2-D အုပ်စု တွင် အကိရိယာ ကို ဝေးဝေးခြင်း ဖြင့် အချက်အလက် ကို အချက်အလက် ကို ကိုယ်စားပြုနိုင်ပါသည်。

Example

1-မြောက် ကွက် တွင် 2-မြောက် အကိရိယာ ကို ဖတ်ရှုရန်

import numpy as np
arr = np.array([[1,2,3,4,5], [6,7,8,9,10]])
print('2nd element on 1st dim: ', arr[0, 1])

လုပ်ကျင်ခြင်း

Example

2-မြောက် ကွက် တွင် 5-မြောက် အကိရိယာ ကို ဖတ်ရှုရန်

import numpy as np
arr = np.array([[1,2,3,4,5], [6,7,8,9,10]])
print('5th element on 2nd dim: ', arr[1, 4])

လုပ်ကျင်ခြင်း

3-D အုပ်စု ကို ဖတ်ရှုရန်

ဒီ 3-D အုပ်စု တွင် အကိရိယာ ကို ဝေးဝေးခြင်း ဖြင့် အချက်အလက် ကို အသုံးပြု၍ အကိရိယာ အခြေအနေ နှင့် အရည်အချင်း ကို အချက်အလက် ကို ကိုယ်စားပြုနိုင်ပါသည်。

Example

访问第一个数组的第二个数组的第三个元素:

import numpy as np
arr = np.array([[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]])
print(arr[0, 1, 2])

လုပ်ကျင်ခြင်း

例子解释

arr[0, 1, 2] Print value 6.

Working principle:

The first number represents the first dimension, which contains two arrays:

[[1, 2, 3], [4, 5, 6]]

Then:

[[7, 8, 9], [10, 11, 12]]

Because we selected 0Therefore, the remaining first array is:

[[1, 2, 3], [4, 5, 6]]

The second number represents the second dimension, which also contains two arrays:

[1, 2, 3]

Then:

[4, 5, 6]

Because we selected 1Therefore, the remaining second array is:

[4, 5, 6]

The third number represents the third dimension, which contains three values:

4
5
6

Because we selected 2Therefore, the final value is the third value:

6

Negative indexing

Use negative indexing to access the array from the end.

Example

Print the last element of the second dimension:

import numpy as np
arr = np.array([[1,2,3,4,5], [6,7,8,9,10]])
print('Last element from 2nd dim: ', arr[1, -1])

လုပ်ကျင်ခြင်း