I want to delete a combination of arrays specified in Python's three-dimensional array.

Asked 1 years ago, Updated 1 years ago, 410 views

I would like to delete [[23][01][01]] which is the opposite combination of [[01][23]] in Python's three-dimensional ndarray array as shown below.

import numpy as np


arr1 = np.array([[0,1], [2,3]],
                 [[4, 5], [6, 7]],
                 [[2, 3], [0, 1]],
                 [[2, 3], [4, 5]],
                 [[6, 7], [4, 5]],])

arr2 = np.array([[0,1], [2,3]],
                 [[4, 5], [6, 7]],
                 [[2, 3], [4, 5]],])

I would appreciate it if you could let me know as it is not going well.
Thank you for your cooperation.

python python3 numpy array

2023-03-05 07:15

1 Answers

If you don't mind changing the order:

import numpy as np

arr1 = np.array(
    [[[0, 1], [2, 3]],
     [[4, 5], [6, 7]],
     [[2, 3], [0, 1]],
     [[2, 3], [4, 5]],
     [[6, 7], [4, 5]]])

print(np.unique(np.sort(arr1,axis=1),axis=0))

# [[[0 1]
#   [2 3]]
# 
#  [[2 3]
#   [4 5]]
# 
#  [[4 5]
#   [6 7]]]


2023-03-06 00:27

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.