Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

I’m trying to predict a next step position (using latitude and longitude as attributes and target). I’ve tried the following:

pred = gmm.predict(len(X)+i, np.array([X[(num-1)+i]])) where the first value is 10 and the second “array([[41.4051453, 2.1776344]])” with shape (1, 2)

however, I get this error:

`AttributeError: ‘list’ object has no attribute ‘shape’

What I’m doing wrong? `

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

raul-paradacommented, May 5, 2021

It works!

AlexanderFabischcommented, May 5, 2021

That’s because the predict function expects an array of shape (n_samples, n_features), but the shape is (n_features,). This version works for me:

    states = np.array([[41.4049364, 2.177356],
                       [41.4049656, 2.1773926],
                       [41.4049938, 2.1774287],
                       [41.4050204, 2.1774638],
                       [41.4050453, 2.1774975],
                       [41.4050682, 2.1775296],
                       [41.4050895, 2.1775597],
                       [41.4051093, 2.1775874],
                       [41.4051278, 2.1776125],
                       [41.4051453, 2.1776344]])
    state_tuples = np.hstack((states[:-1], states[1:]))

    gmm = GMM(n_components=3, random_state=0)
    next_state = gmm.predict(np.array([0, 1]), [states[-1]])
    assert_array_almost_equal(next_state, [[41.405162, 2.177657]])

On the current master branch, otherwise you have to cast all lists to numpy arrays.

Read more comments on GitHub >

github_iconTop Results From Across the Web

'list' object has no attribute 'shape' - python - Stack Overflow
list object in python does not have 'shape' attribute because 'shape' implies that all the columns (or rows) have equal length along certain ......
Read more >
AttributeError: 'list' object has no attribute 'shape' | bobbyhadz
The Python "AttributeError: 'list' object has no attribute 'shape'" occurs when we try to access the shape attribute on a list. To solve...
Read more >
AttributeError: 'list' object has no attribute 'shape'
AttributeError : 'list' object has no attribute 'shape' ... Based on the error messages it seems that feats is a list , while...
Read more >
PYTHON : 'list' object has no attribute 'shape' - YouTube
PYTHON : ' list ' object has no attribute ' shape ' [ Gift : Animated Search Engine : ] PYTHON :...
Read more >
'list' object has no attribute 'reshape' ( Solved )
The solution for this attributeError is very simple. If you want to change the shape or dimensions of the array then firstly convert...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found