Python Forum
comparing floating point arrays to arrays of integers in Numpy
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
comparing floating point arrays to arrays of integers in Numpy
#1
I am using sklearns OneHotEncoder and MultiLabelBinarizer to one-hot encode some target labels.

I am working on a multi-label classification task and am one-hot encoding my targets.

I have been using OnehotEncoder principally however I have done the encoding also using MultiLabelBinarizer just to be sure that target encodings are both done correctly. They are, however the dtype of OneHotEncoder is 'float64' by default while for MultiLabelBinarizer is 'int64'... A preview of each is as follows:


MultiLabelBinarizer
array([[1, 0, 0, ..., 0, 0, 0],
       [0, 1, 0, ..., 0, 0, 0], .... etc

OneHotEncoder
array([[1., 0., 0., ..., 0., 0., 0.],
       [0., 1., 0., ..., 0., 0., 0.], ... etc
When I compare these two arrays using np.array_equal()

np.array_equal(mlb, ohe) #variables of the above although I haven't shown the code that generates it..
The arrays are identical (boolean = True)

This is good as it confirms both encoders one-hot encode my target labels the same way.. My question though is:

Why does it show true, even though the encodings themselves are correct - the data types are different, one with a floating point and one without, how is this behaviour explained?


thank you!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Numpy] How to store different data type in one numpy array? water 7 551 Mar-26-2024, 02:18 PM
Last Post: snippsat
  Pandas dataframes and numpy arrays bytecrunch 1 1,329 Oct-11-2022, 08:08 PM
Last Post: Larz60+
  Build Lapalce symbolic expression from nominator/denominator arrays Pavel_47 0 859 Oct-07-2022, 01:35 PM
Last Post: Pavel_47
  Turn list of arrays into an array of lists Cola_Reb 6 1,712 Jul-20-2022, 06:55 PM
Last Post: Cola_Reb
  Numpy returns "TypeError: unsupported operand type(s) for *: 'numpy.ufunc' and 'int'" kalle 2 2,607 Jul-19-2022, 06:31 AM
Last Post: paul18fr
  Write a dictionary with arrays as values into JSON format paul18fr 3 5,635 Oct-20-2021, 10:38 AM
Last Post: buran
  Arrays faster than pandas? Mark17 4 2,841 Aug-02-2021, 03:14 PM
Last Post: Mark17
  Concatenate 3D arrays paul18fr 1 2,646 Apr-09-2021, 02:49 PM
Last Post: paul18fr
  Automating to generate multiple arrays Robotguy 1 1,801 Nov-05-2020, 08:14 AM
Last Post: Gribouillis
  Using Pytables to Sort Large Arrays? Robotguy 0 2,006 Aug-12-2020, 03:35 PM
Last Post: Robotguy

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020