How to make python object callable by numpy.array()

Ziofil

Some classes, such as Series in pandas produce instances that can be called by numpy.array and turned into numpy arrays.

How do I make instances of a class that I'm writing (which works with a few arrays at the core) be allowed to be passed as argument to numpy.array and converted to a numpy array?

(perhaps "callable" is not the right word)

interfect

It looks like one easy way is to make the object define an __array__(self) method that returns the array you want numpy.array to return.

You can also make your object a sequence: define __iter__(self) to return an iterator over all the items, __getitem__(self, i), to return the ith element, and and __len__(self) to return the length.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to make a generator callable?

Can you make an object 'callable'?

How can I map python callable over numpy array in both elegant and efficient way?

How can I make an object callable?

'Index' object is not callable in python

How to make video from an updating numpy array in Python

Python + Numpy : TypeError: 'int' object is not callable

Python declare numpy array 'tuple' is not callable (in jupyter notebook?)

TypeError: 'numpy.ndarray' object is not callable within for loop Python

Repeat rows of an array N times depending on the length of my df in a for loop is not working. Error 'numpy.ndarray' object is not callable" (Python)

How to make numpy 2D array back into python list

How to fix python error (object is not callable)

How to define a callable object into another python class

How to fix 'AffinityPropagation object is not callable' error in Python

How to construct a callable from a Python code object?

How to make globally callable python program?

why numpy.ndarray is object is not callable in my simple for python loop

Python 'dict' object not callable?

How to make Python object behave like a numpy array?

Python - 'int' object is not callable

How to make an array of functions callable in python

object is not callable in function of least_squares, how to make it callable?

How to create a truly callable array or matrix in Python

Python: 'numpy.float64' object is not callable

Python: 'list' object is not callable

how to overcome the "'numpy.ndarray' object is not callable" error?

How to address 'module' object not callable in python selenium

How to make middleware object callable in Django 2.2

Python: how to solve "TypeError: 'str' object is not callable"