Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Using numpy getting error: module numpy has no attribute 'flip' - yet it does!!!
-
So, I am writing some code using my Mac, that I am then saving on iCloud and reading into my iPad. All works well... alas...
I am using the numpy library, and though this runs perfectly on the Mac, when the script reaches the third line here:
import numpy as np [my code here] print(np.flip(board, 0))
I get the following error in Pythonista
Attribute error:
Module numpy has no attribute 'flip'Can anyone offer any advice for me, please?
-
The method flip was introduced in numpy 1.12.0.
Pythonista ships with numpy 1.8.0, so this feature is not included. You have to wait for a new Pythonista version, which will most likely include a later version of numpy. -
@themusicman Temporary, source code is here
-
Many thanks both! Still learning, so very grateful for your expertise.
So @cvp - may I ask how I would install that source code into Pythonista please?
-
@themusicman I'm really sorry, I am very far from being a Python specialist and I am sure that many others in this forum will help you, but what I could do is:
import numpy as np def flip(m, axis): if not hasattr(m, 'ndim'): m = asarray(m) indexer = [slice(None)] * m.ndim try: indexer[axis] = slice(None, None, -1) except IndexError: raise ValueError("axis=%i is invalid for the %i-dimensional input array" % (axis, m.ndim)) return m[tuple(indexer)] np.flip = flip board = np.arange(8).reshape((2,2,2)) print(board) print(np.flip(board, 0))
-
Thanks @cvp, I simply used this instead:
import numpy as np reverse_board = board[::-1] print(reverse_board)
which reversed the individual items in the board array such that as there are 7 items in the array, board[0] becomes board[6], board[1] becomes board[5] etc...
Now to work on SpriteNodes - something I have never ever used. Need to figure out how to draw shapes et al.
-
@themusicman I never used it also but this forum is full of examples
-
I have been hitting the old NumPy wall a lot of times lately, as it is a very frequent dependency in other packages (for instance
astropy
and its affiliated packages likeastroplan
). NumPy 1.8.0 is now about 6 years old, which makes it very like to be an issue for almost any packages that requires it. Simply too old.