m1 = [0,1,1,3]
m2 = [0,0,1,1]
data = [10,20,30,40]
Tôi muốn làm điều gì đó như thế này:
mask = [m1 == 1] & [m2 == 1]
data[mask] #should return 30
Lưu ý, ví dụ này dẫn đến một lỗi
Jaime
63,9K17 Huy hiệu vàng120 Huy hiệu bạc158 Huy hiệu đồng17 gold badges120 silver badges158 bronze badges
Đã hỏi ngày 22 tháng 3 năm 2013 lúc 20:24Mar 22, 2013 at 20:24
1
Bạn đang sử dụng danh sách Python thay vì các mảng Numpy. Thay vào đó hãy thử điều này:
import numpy as np
m1 = np.array[[0,1,1,3]]
m2 = np.array[[0,0,1,1]]
mask = [m1 == 1] & [m2 == 1]
data[mask]
# returns array[[30]]
Trong ví dụ của bạn, khi
import numpy as np
m1 = np.array[[0,1,1,3]]
m2 = np.array[[0,0,1,1]]
mask = [m1 == 1] & [m2 == 1]
data[mask]
# returns array[[30]]
8 là một danh sách, import numpy as np
m1 = np.array[[0,1,1,3]]
m2 = np.array[[0,0,1,1]]
mask = [m1 == 1] & [m2 == 1]
data[mask]
# returns array[[30]]
9 được đánh giá là >>> m1 = np.ma.make_mask[[0, 1, 1, 0]] >>> m2 = np.ma.make_mask[[1, 0, 0, 0]] >>> np.ma.mask_or[m1, m2] array[[ True, True, True, False]]0 [giống nhau đối với
>>> m1 = np.ma.make_mask[[0, 1, 1, 0]] >>> m2 = np.ma.make_mask[[1, 0, 0, 0]] >>> np.ma.mask_or[m1, m2] array[[ True, True, True, False]]1], vì vậy mặt nạ là
>>> m1 = np.ma.make_mask[[0, 1, 1, 0]] >>> m2 = np.ma.make_mask[[1, 0, 0, 0]] >>> np.ma.mask_or[m1, m2] array[[ True, True, True, False]]0 và
>>> m1 = np.ma.make_mask[[0, 1, 1, 0]] >>> m2 = np.ma.make_mask[[1, 0, 0, 0]] >>> np.ma.mask_or[m1, m2] array[[ True, True, True, False]]3.
Đã trả lời ngày 22 tháng 3 năm 2013 lúc 20:27Mar 22, 2013 at 20:27
Tiagotiagotiago
21.8K11 Huy hiệu vàng71 Huy hiệu bạc86 Huy hiệu đồng11 gold badges71 silver badges86 bronze badges
6
Kết hợp hai mặt nạ với toán tử
>>> m1 = np.ma.make_mask[[0, 1, 1, 0]] >>> m2 = np.ma.make_mask[[1, 0, 0, 0]] >>> np.ma.mask_or[m1, m2] array[[ True, True, True, False]]4.
Kết quả có thể là chế độ xem trên M1 hoặc M2 nếu cái kia là
>>> m1 = np.ma.make_mask[[0, 1, 1, 0]] >>> m2 = np.ma.make_mask[[1, 0, 0, 0]] >>> np.ma.mask_or[m1, m2] array[[ True, True, True, False]]5 [tức là sai].Tham số1, m2array_likem1, m2array_like
Mặt nạ đầu vào.
Copybool, tùy chọnbool, optionalNếu bản sao là sai và một trong các đầu vào là
>>> m1 = np.ma.make_mask[[0, 1, 1, 0]] >>> m2 = np.ma.make_mask[[1, 0, 0, 0]] >>> np.ma.mask_or[m1, m2] array[[ True, True, True, False]]5, hãy trả về chế độ xem mặt nạ đầu vào khác. Mặc định là sai.co lại, tùy chọnbool, optional
Có nên thu nhỏ đầu ra xuống
>>> m1 = np.ma.make_mask[[0, 1, 1, 0]] >>> m2 = np.ma.make_mask[[1, 0, 0, 0]] >>> np.ma.mask_or[m1, m2] array[[ True, True, True, False]]5 nếu tất cả các giá trị của nó là sai. Mặc định là đúng.ReturnSmaskOutput Maskmaskoutput mask
Các giá trị mặt nạ kết quả được che trong M1 hoặc M2.
RAISEVALUEERRORNếu M1 và M2 có các DTYpes linh hoạt khác nhau.
Ví dụ
>>> m1 = np.ma.make_mask[[0, 1, 1, 0]] >>> m2 = np.ma.make_mask[[1, 0, 0, 0]] >>> np.ma.mask_or[m1, m2] array[[ True, True, True, False]]
Sau đây là 24 ví dụ mã của mặt nạ.merge []. Bạn có thể bỏ phiếu cho những người bạn thích hoặc bỏ phiếu cho những người bạn không thích và đi đến dự án gốc hoặc tệp nguồn bằng cách theo các liên kết trên mỗi ví dụ. Bạn cũng có thể muốn kiểm tra tất cả các chức năng/lớp có sẵn của mặt nạ mô -đun hoặc thử chức năng tìm kiếm.24 code examples of mask.merge[]. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module mask, or try the search function
Ví dụ 1
def annToRLE[self, ann]: """ Convert annotation which can be polygons, uncompressed RLE to RLE. :return: binary mask [numpy 2D array] """ t = self.imgs[ann['image_id']] h, w = t['height'], t['width'] segm = ann['segmentation'] if type[segm] == list: # polygon -- a single object might consist of multiple parts # we merge all parts into one mask rle code rles = mask.frPyObjects[segm, h, w] rle = mask.merge[rles] elif type[segm['counts']] == list: # uncompressed RLE rle = mask.frPyObjects[segm, h, w] else: # rle rle = ann['segmentation'] return rle
Ví dụ #2
def annToRLE[self, ann]: """ Convert annotation which can be polygons, uncompressed RLE to RLE. :return: binary mask [numpy 2D array] """ t = self.imgs[ann['image_id']] h, w = t['height'], t['width'] segm = ann['segmentation'] if type[segm] == list: # polygon -- a single object might consist of multiple parts # we merge all parts into one mask rle code rles = mask.frPyObjects[segm, h, w] rle = mask.merge[rles] elif type[segm['counts']] == list: # uncompressed RLE rle = mask.frPyObjects[segm, h, w] else: # rle rle = ann['segmentation'] return rle
Ví dụ #3
def annToRLE[self, ann]: """ Convert annotation which can be polygons, uncompressed RLE to RLE. :return: binary mask [numpy 2D array] """ t = self.imgs[ann['image_id']] h, w = t['height'], t['width'] segm = ann['segmentation'] if type[segm] == list: # polygon -- a single object might consist of multiple parts # we merge all parts into one mask rle code rles = mask.frPyObjects[segm, h, w] rle = mask.merge[rles] elif type[segm['counts']] == list: # uncompressed RLE rle = mask.frPyObjects[segm, h, w] else: # rle rle = ann['segmentation'] return rle
Ví dụ #4
def annToRLE[self, ann]: """ Convert annotation which can be polygons, uncompressed RLE to RLE. :return: binary mask [numpy 2D array] """ t = self.imgs[ann['image_id']] h, w = t['height'], t['width'] segm = ann['segmentation'] if type[segm] == list: # polygon -- a single object might consist of multiple parts # we merge all parts into one mask rle code rles = mask.frPyObjects[segm, h, w] rle = mask.merge[rles] elif type[segm['counts']] == list: # uncompressed RLE rle = mask.frPyObjects[segm, h, w] else: # rle rle = ann['segmentation'] return rle
Ví dụ #5
def annToRLE[self, ann]: """ Convert annotation which can be polygons, uncompressed RLE to RLE. :return: binary mask [numpy 2D array] """ t = self.imgs[ann['image_id']] h, w = t['height'], t['width'] segm = ann['segmentation'] if type[segm] == list: # polygon -- a single object might consist of multiple parts # we merge all parts into one mask rle code rles = mask.frPyObjects[segm, h, w] rle = mask.merge[rles] elif type[segm['counts']] == list: # uncompressed RLE rle = mask.frPyObjects[segm, h, w] else: # rle rle = ann['segmentation'] return rle
Ví dụ #6
def annToRLE[self, ann]: """ Convert annotation which can be polygons, uncompressed RLE to RLE. :return: binary mask [numpy 2D array] """ t = self.imgs[ann['image_id']] h, w = t['height'], t['width'] segm = ann['segmentation'] if type[segm] == list: # polygon -- a single object might consist of multiple parts # we merge all parts into one mask rle code rles = mask.frPyObjects[segm, h, w] rle = mask.merge[rles] elif type[segm['counts']] == list: # uncompressed RLE rle = mask.frPyObjects[segm, h, w] else: # rle rle = ann['segmentation'] return rle
Ví dụ #7
def annToRLE[self, ann]: """ Convert annotation which can be polygons, uncompressed RLE to RLE. :return: binary mask [numpy 2D array] """ t = self.imgs[ann['image_id']] h, w = t['height'], t['width'] segm = ann['segmentation'] if type[segm] == list: # polygon -- a single object might consist of multiple parts # we merge all parts into one mask rle code rles = mask.frPyObjects[segm, h, w] rle = mask.merge[rles] elif type[segm['counts']] == list: # uncompressed RLE rle = mask.frPyObjects[segm, h, w] else: # rle rle = ann['segmentation'] return rle
Ví dụ #8
def annToRLE[self, ann]: """ Convert annotation which can be polygons, uncompressed RLE to RLE. :return: binary mask [numpy 2D array] """ t = self.imgs[ann['image_id']] h, w = t['height'], t['width'] segm = ann['segmentation'] if type[segm] == list: # polygon -- a single object might consist of multiple parts # we merge all parts into one mask rle code rles = mask.frPyObjects[segm, h, w] rle = mask.merge[rles] elif type[segm['counts']] == list: # uncompressed RLE rle = mask.frPyObjects[segm, h, w] else: # rle rle = ann['segmentation'] return rle
Ví dụ #9
mask = [m1 == 1] & [m2 == 1]
data[mask] #should return 30
2Ví dụ #10
mask = [m1 == 1] & [m2 == 1]
data[mask] #should return 30
2Ví dụ #11
mask = [m1 == 1] & [m2 == 1]
data[mask] #should return 30
2Ví dụ #12
mask = [m1 == 1] & [m2 == 1]
data[mask] #should return 30
2Ví dụ #13
mask = [m1 == 1] & [m2 == 1]
data[mask] #should return 30
2Ví dụ #14
mask = [m1 == 1] & [m2 == 1]
data[mask] #should return 30
2Ví dụ #15
mask = [m1 == 1] & [m2 == 1]
data[mask] #should return 30
2Ví dụ #16
mask = [m1 == 1] & [m2 == 1]
data[mask] #should return 30
2Ví dụ #17
mask = [m1 == 1] & [m2 == 1]
data[mask] #should return 30
2Ví dụ #18
mask = [m1 == 1] & [m2 == 1]
data[mask] #should return 30
2Ví dụ #19
mask = [m1 == 1] & [m2 == 1]
data[mask] #should return 30
2Ví dụ #20
mask = [m1 == 1] & [m2 == 1]
data[mask] #should return 30
2Ví dụ #21
mask = [m1 == 1] & [m2 == 1]
data[mask] #should return 30
2Ví dụ #22
mask = [m1 == 1] & [m2 == 1]
data[mask] #should return 30
2Ví dụ #23
mask = [m1 == 1] & [m2 == 1]
data[mask] #should return 30
2Ví dụ #24
mask = [m1 == 1] & [m2 == 1]
data[mask] #should return 30
2