Home > Back-end >  What did pylab.find() do while it was still existing?
What did pylab.find() do while it was still existing?

Time:09-30

I have an inherited code where there's a line using pylab.find():

import numpy
import pylab
xsnp['q'] = numpy.array([xsnp['ff'][pylab.find(xsnp['T']==x), 0] for x in xsnp['xyz']]).reshape(N,)

(xsnp is a dict of Numpy arrays).

However, this method does not seem to be available anymore as the line above causes a

AttributeError: module 'pylab' has no attribute 'find'

I could not find it using Google anywhere. Numpy doesn't seem to have a find() function and Pylab is a godawful mess of a ton of star-import from different modules, so I have no idea where to look.

What was pylab.find(), and what could I replace it with?

CodePudding user response:

From the Matplotlib API Changes for 3.1.0:

pylab removals

Lots of code inside the matplotlib.mlab module which was deprecated in Matplotlib 2.2 has been removed. This means the following functions are no longer available in the pylab module:

...

  • find (use np.nonzero(np.ravel(condition)) instead)

Note, to replicate the behavior of find, you will need to extract the first element of the tuple returned by np.nonzero(np.ravel(condition)).

(For reference, I found this by searching for pylab.find in the Matplotlib documentation after reading the below question.)

Related question: matplotlib versions >=3 does not include a find()

  • Related