Upgrading from scipy to imageio - python-3.x

I'm quite new to Python so bear with me, I downloaded a github project for Document Forgery Detection that works with 3.6 and buried within it is scipy.misc.imsave which is deprecated.
The call to scipy.misc.imsave only has one parameter but I can't find documentation for that call, only for two parameter methods.
So when I tried to upgrade to what I found recommended online, imageio I replaced the calls as so.
Before
scipy.misc.imsave(self.imageOutputDirectory + "MarkedImage")
After
imageio.imwrite(self.imageOutputDirectory + "MarkedImage")
Of course this doesn't work as it expects two params. The problem is I can't figure out what the original implementation was somehow passing to scipy to reference it, is it some inherited method in the class?

Related

How can I use the relax() method in pyscipopt?

Here is some python code that illustrates the problem:
from pyscipopt import Model
master = Model("master LP")
relax = master.relax()
This generates the error:
builtins.AttributeError: 'pyscipopt.scip.Model' object has no attribute 'relax'
These python statements are taken from SCIP documentation --- section Column generation method for the cutting stock problem.
Note, I am using Python 3.6.5 and pyscipopt 3.0.2
The relax method does not exist in PySCIPOpt.
What you link to is a book that, I think, was originally written for using Gurobi's python interface. The authors started translating it to use it with SCIP but this is not ready yet. Actually, you can even see it in the Todo at the beginning of the page you link to.
In any case, this is not the documentation of SCIP
Check the pyscipopt github page and if you have further problems/questions, please open an issue there

TypeError: can't pickle dict_keys objects calling mdl.solve() in cplex

I have an OR problem and using an academic version of cplex library in the jupyter notebook by python 3.6.
When I am calling the following command I get an error:
command:
solution=mdl.solve(log_output=True)
error:
TypeError: can't pickle dict_keys objects
when I removed (log_output=True) everything works just fine, but I need the detailed output.
Since this is a crossed reference question, I would rather not repeat myself and confuse other people. The reason to ask here is that different scholars are attending these two reference webpages.
https://github.com/IBMDecisionOptimization/docplex-examples/issues/14
If I find my answer in stackoverflow I will share the solution procedure here and on github.
From the solution found in the external link: the problem is fixed in docplex ersion 2.10.150. Upgrading to that version fixes the problem.
As Daniel Junglas mentioned there were some inconsistencies between the two version of docplex toolbox and cplex 12.9 academic version I was using. A member of IBM team noticed the problem and updated the docplex version. And the lastest version up to date 07/08/2019 is here https://pypi.org/project/docplex/2.10.150/.
Many thanks to IBM Team.

Has basemap become outdated?

I'm currently coding Python 3.6 and using basemap 1.0.7. I am running into problems with the toolkit, which seems to be because it is using now-deprecated functions of matplotlib. Just to name a few:
"MatplotlibDeprecationWarning: axes.hold is deprecated"
"MatplotlibDeprecationWarning: The get_axis_bgcolor function was deprecated in version 2.0. Use get_facecolor instead."
I can't follow the guides, due to limited/missing functionality.
Questions tagged with matplotlib-basemap seem to be somewhat active. Am I missing something? Are people still having success with basemap? If not, are there some alternatives available? I've looked at plotly, vincent, and geoplotlib. I've run into deprecation errors using the latter two, and I'd like something completely open, not requiring sign-up as Plotly.

gensim KeydVectors dimensions

Im gensims latest version, loading trained vectors from a file is done using KeyedVectors, and dosent requires instantiating a new Word2Vec object. But now my code is broken because I can't use the model.vector_size property. What is the alternative to that? I mean something better than just kv[kv.index2word[0]].size.
kv.vector_size still works; I'm using gensim 2.3.0, which is the latest as I write. (I am assuming kv is your KeyedVectors object.) It appears object properties are not documented on the API page, but auto-complete suggests it, and there is no deprecated warning or anything.
Your question helped me answer my own, which was how to get the number of words: len(kv.index2word)

How can I load Raphael within IPython notebook, avoiding some issues that arise due to require.js?

In an IPython notebook, one would expect the following code to cause Raphael.js to load successfully into the global namespace.
from IPython.display import Javascript
raphael_url = "https://cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"
Javascript('alert(Raphael);', lib=[raphael_url])
However, it does not work in recent versions of IPython which use require.js. Turns out, Raphael.js, which IPython loads using jQuery.getScript(), recognizes the presence of require.js and as such does not insert itself into the global namespace. In fact, if one first runs javascript code removing the window.define object, Raphael no longer realizes require.js is present, and it inserts itself into the global namespace as I would like. In other words, the code above works after running the following:
Javascript('window.define = undefined;')
Thus, the only way I am able to get Raphael to load within a recent version of IPython notebook is to delete (or set aside) window.define.
Having identified the problem, I am not familiar enough with require.js to know what piece of software is acting against protocol. Is Raphael using a poor way of testing for the existence of require.js? Should IPython be using require.js directly instead of jQuery.getScript() when it loads user-provided javascript libraries? Or is there a way I as the user ought to be embracing require.js, which will give me the Raphael object without needing any special hacks? (If the answer to the last question is yes, is there a way I can also support older versions of IPython notebook, which do not use require.js?)
The first part of my answer won't please you, but the loading and requirement of javascript library in the IPython-notebook-webapp has not yet been solved, so for now I would suggest not to build to much on the assumption you can load library like that, and rely more on custom.js for now.
That being said, if raphael is not in global namespace require is smart enough to cache it, and give you reference to it. Then in the callback you can just assign to a global :
require(['raphael'], function( raph ){
window.raphael = raph;
})
Or something like that should do the trick.

Resources