0

I have a multidimensional array in this form:

array = [[3, 5],
        [2, 5],
        [9, 7],
        [3, 5]]

I need it to return:

array = [[3, 5],
        [2, 5],
        [9, 7]]

I have tried set(array) but that does not work. Help.

  • What you show is not called an array in Python, but a *list*. It is not "multidimensional", but simply contains more lists - the `list` datatype does not enforce any kind of consistent structure with regard to size, shape or number of dimensions. When used to contain more lists, it is more like an arbitrary-width tree than a multidimensional array. Based on your question history, it seems that you are generally confused about this, and it is really important to get it straight now. If you use Numpy arrays, those are a *completely different kind of thing* from Python's built-in `list`. – Karl Knechtel Jul 02 '22 at 21:41

1 Answers1

-1

This code works.

import numpy as np 
a = np.array([[3, 5],
        [2, 5],
        [9, 7],
        [3, 5]])
print(a)
#remove the duplicate sub-arrays
b = np.unique(a,axis=0)
print(b)
Mercury
  • 298
  • 1
  • 11
  • Please don't assume that Python questions from new users - especially ones that seem to be about fairly basic material - are about Numpy, just because they use the word "array". It is very common for people to refer to lists wrongly. Questions about Numpy functionality should be expected to make that explicit. – Karl Knechtel Jul 02 '22 at 21:43
  • I got that, i just assumed that converting the array into numpy format, such as by doing a = np.array(a), would allow the problem to be solved super easily. If need be it an always be converted back to a list by using b.tolist(). – Mercury Jul 02 '22 at 21:47