0

I have this line that build a 2d array

ResultsArray = multilabel_binarizer.transform(results_df['result'])

when I get ResultsArray values I get this

ResultsArray
Out[104]: 
array([[0, 0, 0, ..., 0, 0, 1],
       [0, 0, 0, ..., 0, 0, 1],
       [0, 0, 0, ..., 0, 0, 1],
       ...,
       [0, 0, 0, ..., 0, 0, 1],
       [0, 1, 0, ..., 0, 0, 1],
       [0, 0, 0, ..., 0, 0, 1]])

When I try to build my own 2d array like this

a = [["A1","A2","A3"],["B1","B2","B3"],["C1","C2","C3"]]

a
Out[123]: [['A1', 'A2', 'A3'], ['B1', 'B2', 'B3'], ['C1', 'C2', 'C3']]

when I do the shape of the ResultsArray

ResultsArray.shape
Out[126]: (999, 25)

but for my array a

I get error

a.shape

Traceback (most recent call last):

  File "<ipython-input-127-d6da0fa94082>", line 1, in <module>
    a.shape

AttributeError: 'list' object has no attribute 'shape'

how to create an 2d array that has same properties as ResultsArray

2
  • numpy array has attribute shape, not python list Commented Mar 30, 2020 at 5:45
  • Does this answer your question? 'list' object has no attribute 'shape' Commented Mar 30, 2020 at 6:18

1 Answer 1

2

That's because what you're creating is a Python's list which does not have the shape attribute, while multilabel_binarizer.transform returns a numpy.array.

You can wrap your list in numpy.array to make it the same:

import numpy

a = numpy.array([["A1","A2","A3"],["B1","B2","B3"],["C1","C2","C3"]])
a.shape
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.