Reputation: 8014
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
Upvotes: 0
Views: 35
Reputation: 333
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
Upvotes: 2