News for hackers. Stuff that matters.
Re:New IPython release drops Python 2.7 support by breatheoften on Thursday April 20, 2017 @12:40PM (#14158269)
A comment from a beginner python user -- but I need to rant ...

I've been doing a bit of python the last few weeks for some image processing/computer vision tasks (using opencv and numpy).

I have to say, all together it's a pretty miserable developer experience.

Python is incredibly slow - forcing pretty much all computation no matter how trivial into contortions via numpy incantations so that the inner loops can run in native extensions -- these Incantations have a lot of implicit not well documented magic. Miss some details in the behavior of the magic and suddenly you have a major 10x slowdown -- but good luck finding where. I would kill for an easy to use tool like xcodes Time Profiler ...

API usage errors (even those where invariants are checked at runtime) are ridiculously under informative -- opencv for example does quite a bit of runtime sanity checking on the shape and type of arguments to its methods -- but somehow even simple details as to which parameter is the cause of the error don't get reported in the stack trace severely increasing the cognitive load required to identify the mismatch -- not fun when multiple arguments to an API are the result of a chain of numpy magic data munging. This may be an opencv complaint more than python (aside: opencv is pretty terrible.)

I'm not sure what I'm doing wrong with python but I find the majority of my code to be sort of menial data munging -- and I haven't figured out good patterns to organize this munging in any sensical way --with a static language d.r.y patterns to centralize such plumbing operations have the awesome effect of moving invariants into reasonable places -- in python without any ability to organjze guarantees, as the code base evolves I find myself needing to repeatedly check data shapes/types -- there doesn't seem to be an obviously useful way to organize verification of data types as the necessary invariants become apparent. These issues are compounded by the fact that refactoring is an enormous pain in the ass!

I feel like all my python code is throwaway code. Maybe that's what I'm missing -- I need to just accept that all the python numeric code I write is pure one-off junk, embrace copy paste and never try to reuse any of it ...

Sorry for the rant! I remember loving dynamic languages when I first discovered them - but right now, I really miss c++ (or even better swift).

I can't imagine the number of hours wasted because of these overly dynamic tools -- and there is simply no decreasing that lost time in the future -- as these languages grow if the house of cards ecosystems they sit atop grow and motivates more use then ever more developer hours will be lost to avoidable triviality ...

Re:New IPython release drops Python 2.7 support by abhirag on Thursday April 20, 2017 @01:11PM (#14158628)
"I would kill for an easy to use tool like xcodes Time Profiler" -- maybe this(https://www.visualstudio.com/vs/debugging-and-diagnostics/) can help. "I really miss c++ (or even better swift)." -- maybe this(http://mypy-lang.org/) can help. I am just trying to help and have no intention of going into static vs dynamic typing but if you want to do data science stuff in a statically typed language, you should have a look at F# and its type providers(http://fsharp.org/guides/data-science/). I personally don't agree with a few of your criticisms of python, but you needed to rant so I'll just ignore them :)
Re:New IPython release drops Python 2.7 support by abhirag on Thursday April 20, 2017 @01:14PM (#14158658)
Sorry, I forgot giving a link to Python Tools for Visual Studio which includes the debugging and profiling utilities I linked to(https://www.visualstudio.com/vs/python/).
Re:New IPython release drops Python 2.7 support by jpfr on Thursday April 20, 2017 @06:38PM (#14161532)

   forcing pretty much all computation no matter how trivial
   into contortions via numpy incantations so that the inner
   loops can run in native extensions
That's actually a big plus in my book.

Welcome to the development of Matlab-style code. It can be pretty disheartening to see a complicated hand-crafted algorithm replaced by, say, a matrix multiplication. Try to find Matlab/numpy implementations from paper authors. This programming style is a bit difficult to get used to initially. But it will become incredibly powerful as you start thinking in algebraic operations.

Also, don't do debug runs on the full data. Implement ideas with a subset that computes fast. Then simplify the code and make it fast. Then run it on the full dataset.

If you absolutely need to combine linear algebra operations with fast imperative code, have a go at the Julia language [1] or use a C++ library like Eigen [2] or Armadillo [3].

[1] https://julialang.org/

[2] http://eigen.tuxfamily.org/index.php?title=Main_Page

[3] http://arma.sourceforge.net/

Re:New IPython release drops Python 2.7 support by cs702 on Thursday April 20, 2017 @01:06PM (#14158575)
As a longtime user of Python's scientific stack, I understand your pain.

In a practical sense, the libraries that make up the Python scientific stack -- numpy, pandas, matplolib, sklearn, etc. -- are all akin to domain-specific languages, each with its own magic behavior, quirks, and recommended best practices that one must master. It takes a long while to become proficient in all of them. The good news is that there's a large, growing community of helpful people using these tools, so you can usually find the answer to any question with a single Google search.

For numpy specifically, if you are interested in getting the most out of it with the fewest possible headaches, I would recommend the following online book: http://www.labri.fr/perso/nrougier/from-python-to-numpy/

Otherwise, please make sure to read bmarkovic's spot-on comment in this thread: https://news.ycombinator.com/item?id=14158597

Re:New IPython release drops Python 2.7 support by cold_fact on Thursday April 20, 2017 @04:39PM (#14160625)
Man really? I personally love the Python OpenCv Wrapper.

From a stack-overflow (https://stackoverflow.com/questions/13432800/does-performanc...)... "I remember I read somewhere that performance penalty is <1%, don't remember where. A rough estimate with some basic functions in OpenCV shows a worst-case penalty of <4%".

I'm working on a project that downloads a 2 hour video, frame by frame. Then after, I run image detection on a photo or multiple photos against every single one of those frames.

My code was slow as shit at first. I decided to profile and realized the only speed hog was SIFT's detectAndCompute(). It was taking ~.5s for each frame passed to the algorithm.

So I ended up trading memory for speed and now create huge PyTables loaded with every single frame's KeyPoints and Descriptors. I do this when I first download the videos frames and even though that takes a while, I can now run image detection against 6000 frames (100 minutes) with however many photos in about (24 minutes).

Point is, even just using the built-in cProfile helped a lot because there was only one function that was truly affecting my python. Other than that, I love the python translation. I'm surprised you have memory problems though. OpenCV always murdered my CPU's but never was really memory intensive

Re:New IPython release drops Python 2.7 support by bmarkovic on Thursday April 20, 2017 @01:08PM (#14158597)
The idea of using Python for high performance numerical work is daft. The whole scientific Python thing revolves around the fact that Python is an excellent low boilerplate research and prototyping language with possible production uses where performance isn't critical. Unfortunately this lead to a lot of software in this area being developed for it. You wouldn't be doing performance critical production stuff with R or Matlab? I'm afraid that for serious numbers crunching nothing can truly replace compiled, statically typed languages and additionally you can't rely on GPGPU abstractions without fully understanding the underlying mechanisms and I'm pretty sure that the same is true for NumPy. Your problem are your expectations.
Re:New IPython release drops Python 2.7 support by jacquesm on Thursday April 20, 2017 @05:55PM (#14161264)
I'm doing some pretty heavy image recognition while stitching the output of a camera to image objects larger than the camera can see in one go from two different angles in real time. Python works fine for high performance numerical work, the only thing you have to keep an eye on is to use python as much as possible as the glue and the various libraries written in C or C++ to do the heavy lifting for you (and there are tons of such libraries).

The reason why python is the right tool for this job is because it has such libraries for just about everything, from serial communications to a bunch of hardware driving stepper motors, relays and reading inputs to imaging and number crunching and all the other bits that went into this. I'd have a much harder time achieving the same effect in any other language and likely it would have cost me a lot more time.

Python is not perfect (far from it) but it gets the job done.

Re:New IPython release drops Python 2.7 support by kevin_thibedeau on Thursday April 20, 2017 @01:44PM (#14158985)
You just switch critical sections to Cython. It knows how to handle NumPy objects and you get compiled, statically typed code when it is needed for performance.
Re:New IPython release drops Python 2.7 support by curiousgal on Thursday April 20, 2017 @05:05PM (#14160893)
Numba is a solid option as well.
Re:New IPython release drops Python 2.7 support by breatheoften on Thursday April 20, 2017 @01:58PM (#14159126)
Lots of good replies to this -- and some good links which I am going to follow. I appreciate the comments!

I appreciate this comment as well -- and indeed I will agree that my expectations are part of the problem.

I'm not actually doing 'performance critical' work -- but rather prototyping tasks -- the speed of my feedback cycle is the only thing that's performance sensitive within the context of my rant -- and this includes time to run the code and the time to debug it.

I should also acknowledge other (self-induced) problems including the need to run code on a remote server for extra hardware capability vs my pitiful laptop.

I should acknowledge that part of my frustration could come from my development process as from the inherent nature of the underlying tools themselves ... I've experimented with my process -- trying to find something that works for me and I've ended up with this hobbled kludge of tools:

- a script that re-runs rsync on file changes - atom + hydrogen extension connected via ssh to a jupyter kernel_gateway - some ssh terminals where I run longer running code from command line - an sshfs mount of a remote directory on the server for viewing some output artifacts ...

Avoidable runtime errors after longish-running processing tasks are a very frustrating time-sync ...

Re:New IPython release drops Python 2.7 support by abhirag on Thursday April 20, 2017 @03:37PM (#14160062)
Now that I have a better idea of your dev setup I think I can be of a bit more help :)

1. If you are prototyping and prefer working on a remote server, have a look at(https://notebooks.azure.com/), memory is limited to 4Gb but its free and jupyter notebooks are great for prototyping.

2. For prototyping you should try and do REPL driven development, what I mean is that you should be ok with just playing around with the library API before you write a longish-running processing task, that would reduce(not remove) the chances of a runtime error. Jupyter notebooks excel in this too as you can just try out code in a cell, learn from it, rinse and repeat. You can also use your IDE to send code fragments to REPL and get immediate feedback on them. This way of iterative development would make sure that the speed of your feedback cycle isn't slow. If python's feedback cycle seems slower to you than C++, you are definitely not using the REPL enough :)

3. If debugging is a pain point definitely give an IDE a try, I prefer Visual Studio as I am on Windows. You can very well go with Pycharm or vscode(not technically an IDE but has a debugger so that's that). I personally prefer Jupyter notebook or Emacs with my code and REPL in split windows for prototyping, different strokes for different folks.

I personally love working with python, I even write my blog posts in a Jupyter Notebook so although it isn't perfect, it doesn't have to be frustrating either :) Hope my suggestions can be of some help!

Re:New IPython release drops Python 2.7 support by yongjik on Thursday April 20, 2017 @01:58PM (#14159123)
There's "not for performance-critical use", and then there's "why is it gobbling up all the RAM (~10GB) and make it impossible for me to do anything, when the entire data I fed it is several hundred MB."

Python frequently saunters into the second territory. Well, I guess there are tools available to profile memory usage and stuff, but if I had to spend that much effort tracking down memory issues, I might as well rewrite it in C++. (It doesn't help (or it helps?) that I'm much more comfortable with C++ than Python. YMMV.)

Re:New IPython release drops Python 2.7 support by jacquesm on Thursday April 20, 2017 @05:59PM (#14161291)
There are some easy to avoid pathological cases such as concatenating numpy arrays in a loop.

Take this gem from a well known course:

   np.concatenate([x.next() for i in range(x.nb)])
That looks pretty innocent but it can eat up your memory in an eyeblink if the input is large enough. That's the sort of pitfall that a lot of python code suffers from because the abstractions are just nice enough to make you believe this will work without penalty and without knowing how it is implemented under the hood you're suddenly out a few gigs of ram.
Re:New IPython release drops Python 2.7 support by ofek on Thursday April 20, 2017 @06:36PM (#14161514)
If np.concatenate accepts any iterable, removing the brackets is what you want to do there.
Re:New IPython release drops Python 2.7 support by jzwinck on Thursday April 20, 2017 @09:36PM (#14162455)
That won't help. Concatenate needs to know the total length up front. It will evaluate all the input items at once.
Re:New IPython release drops Python 2.7 support by cookiecaper on Thursday April 20, 2017 @02:12PM (#14159245)
My experience is that Python is much better about this than many other languages in its class, Ruby in particular. It's going to be hard to beat manual pointer/memory management in terms of raw performance, but Python is pretty respectable for an untyped, memory-managed language.
Re:New IPython release drops Python 2.7 support by startupdiscuss on Thursday April 20, 2017 @12:51PM (#14158389)
I have many of the issues you have when I process data, but the issues are with the nature of data-processing, not python. Even in R, or MatLab, I struggle with formatting the data, making sure the size and order of tensors match up for vector calculus operations, and so on.

I think we need a better abstract language for checking matrix algebra operations.

Re:New IPython release drops Python 2.7 support by abhirag on Thursday April 20, 2017 @04:12PM (#14160386)
I think we already have such languages, I would never be able to make better arguments than a Turing award winner so I'll just leave this link(http://www.jsoftware.com/papers/tot.htm) "Notation as a Tool of Thought" by Kenneth E. Iverson.
Re:New IPython release drops Python 2.7 support by fixed_carbon on Thursday April 20, 2017 @01:16PM (#14158681)
I had some of the same frustration with Python, and eventually switched to julia-lang for this kind of stuff. You still don't get the static type analysis step of something like C++ or Haskell, but you can more easily control the types that flow through your computations (compared to python) by using julia's type system. You don't have to deal with numpy's magic, because julia has very nice linear algebra built-ins, and as long as you produce type-stable julia code it's usually plenty fast. There's also an opencv package for julia, although I've never used it.
Re:New IPython release drops Python 2.7 support by muraiki on Thursday April 20, 2017 @05:36PM (#14161157)
I started out learning programming using Python and gradually came to prefer strongly typed languages. I'm aware of 1 1/2 options for doing this kind of work in a strongly typed language that isn't C++:

Option 1: F# or C# with the Deedle[1] library. Deedle provides series and dataframe classes, along with various stats functions. I believe that there are also some vis tools. Type providers in F# allow you to specify a data source, such as a CSV or database, and then not only infer the types but also give you intellisense autocompletion. See the F# guide for data science[2] for more info.

Option 1.5: I hesitate to recommend the following, because there's simply not much here yet, but there is a dataframe library[3] for Nim[4]. Nim is a strongly typed language with a Python-like syntax which compiles to C and is apparently quite fast. It has multiple options for garbage collection but also supports manual memory management. It offers lisp-like macros for implementing DSLs, which the dataframe library I mentioned uses quite a bit. The main problems with Nim are of course the lack of libraries and the need for a notebook-like environment such as Jupyter, which are certainly big problems indeed. But I think that Nim is something to look out for over the next few years.

As much as I like Deedle and F#'s features, I've personally decided to abandon the use of Microsoft technologies due to their many user-unfriendly actions regarding Windows 10 and privacy. I don't fault anyone else for using Deedle, though, because it is a nice tool. This is just a personal decision of mine.

[1] http://bluemountaincapital.github.io/Deedle/ [2] http://fsharp.org/guides/data-science/ [3] https://github.com/bluenote10/NimData [4] https://nim-lang.org

Re:New IPython release drops Python 2.7 support by FridgeSeal on Thursday April 20, 2017 @07:11PM (#14161727)
Whilst Nim doesn't have a REPL/jupyter like environment, I've found that it compiles reasonably quickly, and you can setup Vscode to compile and run on save which can make testing things pretty fast and easy. :)
Re:New IPython release drops Python 2.7 support by throwaway_374 on Thursday April 20, 2017 @07:02PM (#14161667)
>>I started out learning programming using Python and gradually came to prefer strongly typed languages.

Python IS strongly typed. It is also dynamically typed.

Re:New IPython release drops Python 2.7 support by muraiki on Thursday April 20, 2017 @07:54PM (#14161942)
D'oh, I meant statically typed. I blame only getting 3 hours of sleep... :)
Re:New IPython release drops Python 2.7 support by flohofwoe on Thursday April 20, 2017 @01:18PM (#14158694)
I use python for build automation, custom build jobs, code generation for C++, glueing command-line tools together and for multi-platform shell-scripting. For that it is really great. I also had some tasks where vanilla python was simply too slow. In this case I found it easier to move the slow parts into a small cross-platform C++ command line tool and call that from python instead of trying to make the python code faster. YMMV of course :)
Re:New IPython release drops Python 2.7 support by goerz on Thursday April 20, 2017 @01:46PM (#14158999)
Python may just not be good choice of language for your problem. Have you looked at Julia? It claims to be fast for the kinds of things you're doing, and it shares a lot of the Python ecosystem -- the Ju in Jupyter is from Julia, i.e., you can work in notebooks, and you can use existing Python (and C/Fortran) libraries directly. Also, Cython might be an option to speed up your code.
Re:New IPython release drops Python 2.7 support by Cyph0n on Thursday April 20, 2017 @12:51PM (#14158385)
Debugging Python is a pain, but it's an amazingly expressive language and a joy to work with. However, once you find that the cost of debugging outweighs the benefits, you probably should switch to another language. Even more so if you are facing performance issues!

As for myself, the first serious language I taught myself was Python, so I'll always have a soft spot for it. Now that I've begun to realize Python's shortcomings, I've started to work more with statically typed languages; my favorites are Scala and C++, and my next goal is to work with Rust.

Re:New IPython release drops Python 2.7 support by erichurkman on Thursday April 20, 2017 @01:10PM (#14158618)
It's also important to check out other debugging tools for Python. If you're relying on the build in debugger tools, it's a pretty miserable experience. I'm a big fan of pudb [0] that gives a much better experience.

[0] https://pypi.python.org/pypi/pudb

Re:New IPython release drops Python 2.7 support by metaobject on Thursday April 20, 2017 @01:20PM (#14158718)
Why did you feel that you needed to start using Python in the first place? Do you have prior programming experience? Regarding data munging, that's sometimes a significant part of the CV/IP process.

Personally, I love Python. It's been working fairly well for our ML projects utilizing scikit-learn to process fairly large spatiotemporal datasets (temporally varying 2D and 3D datasets). I find numpy to be critical for keeping runtimes reasonable.

Regardless of the language, profiling may be necessary in order to obtain acceptable performance.

Re:New IPython release drops Python 2.7 support by goatlover on Thursday April 20, 2017 @01:35PM (#14158896)
How would C++ help with data munging? No matter what tool you choose, you still have to go through the pain of getting your data into the shape it needs to be in to do the analysis, charting, etc.

Also, Python has plenty of abstraction capabilities, just like C++. There's no reason all your code should be throwaway. Make use of classes, magic methods, list comprehensions, hashes, the Pandas library (lots of powerful abstractions for managing data in there).

Re:New IPython release drops Python 2.7 support by thesmallestcat on Thursday April 20, 2017 @01:50PM (#14159042)
I would kill for an easy to use tool like xcodes Time Profiler ...

PyCharm professional edition comes with a pretty nifty profiler.

Re:New IPython release drops Python 2.7 support by kirkdouglas on Thursday April 20, 2017 @03:39PM (#14160079)
vprof is also quite nice (its free) - https://github.com/nvdv/vprof
Re:New IPython release drops Python 2.7 support by makmanalp on Thursday April 20, 2017 @04:08PM (#14160364)
Wow, I only knew of snakeviz: https://jiffyclub.github.io/snakeviz/

Now, I would kill for the ability to compare two profiles, but putting them on two different tabs will do for now ...

Re:New IPython release drops Python 2.7 support by whalesalad on Thursday April 20, 2017 @07:56PM (#14161955)
All the stuff you're complaining about is stuff that isn't really a python problem. They are definitely valid complaints, but they are with nonstandard things. Numpy is not really Python, it's magic on top of Python. Same goes for OpenCV, which is really just a bridge over to native stuff.

Python is very popular for the use cases you describe, but I have long felt it's akin to using a Honda Civic that has been souped up to be a specialized race car. You can definitely make a Honda fast around a racetrack, but that's not what they were designed to do. You're better off using a purpose built machine.

That being said, a purpose built racecar is harder to drive, doesn't have AC, needs more maintenance, has more expensive tires that wear out faster, etc...

Nothing in life is free, there is always a trade off.

Re:New IPython release drops Python 2.7 support by weberc2 on Thursday April 20, 2017 @04:00PM (#14160296)
You should try Go. It writes quickly like Python, but it's much simpler and more performant. It's also statically typed so you don't have to search all over to figure out the real type of a parameter, etc. Finally, everything compiles into a single static binary, so you don't have to worry about having the right version of an interpreter or libraries installed on your system--just pass around the binary and run it! I also came to it by way of C++ and found it nice that any type can be passed around by value or by reference, unlike Python, Java, etc where everything is a reference and it's hard to tell what (if anything) will be stack allocated. http://tour.golang.org
Re:New IPython release drops Python 2.7 support by _yosefk on Thursday April 20, 2017 @04:20PM (#14160458)
Grandparent is writing numerical code. I doubt that Go which has neither operator overloading nor built-in types such as vector/matrix will work here.
Re:New IPython release drops Python 2.7 support by weberc2 on Saturday April 22, 2017 @11:02AM (#14172855)
Neither operator overloading nor built-in numerical types are necessary (or arguably even useful) for scientific computing. Further, Python also lacks built-in vector/matrix types.
Re:New IPython release drops Python 2.7 support by enriquto on Thursday April 20, 2017 @12:45PM (#14158324)
Python is a great language, but the numpy library is abominable.

With that in mind, you can try to program your numerics code hiding as much as possible the fact that you use numpy. I have found that this is the only barely bearable way to do numerics/image processing in python.

Re:New IPython release drops Python 2.7 support by mertd on Thursday April 20, 2017 @01:18PM (#14158693)
Numpy is not perfect but this is the first time I've heard it being referred to as abominable. What is it doing fundamentally wrong?
Re:New IPython release drops Python 2.7 support by metaobject on Thursday April 20, 2017 @01:25PM (#14158778)
I actually find numpy to be fairly consistent and intuitive. Usually the code ends up being faster and more concise. I love the masking ability of the ndarrays as well as the support for broadcasting operations.
Re:New IPython release drops Python 2.7 support by goatlover on Thursday April 20, 2017 @01:32PM (#14158871)
Yeah, I'm scratching my head over that comment as well.
Re:New IPython release drops Python 2.7 support by newen on Friday April 21, 2017 @01:51AM (#14163366)
Any slightly complicated indexing of array in numpy is a pain. I've spent hours reading the numpy documentation for indexing. After that project I've completely forgotten how to do indexing in numpy. I expect I'll spend more hours reading the same documentation if I ever go back to numpy. Compared to Matlab, it is ridiculously complicated.
Re:New IPython release drops Python 2.7 support by breatheoften on Sunday April 23, 2017 @07:56PM (#14181102)
I don't see how this doesn't lead to a LOT of silently broken code ...

In [3]: x = np.array([1,2,3])

In [4]: x[0:500] Out[4]: array([1, 2, 3])

Re:New IPython release drops Python 2.7 support by enriquto on Thursday April 20, 2017 @05:33PM (#14161129)
Maybe "abominable" is an exaggeration...

However, after translating some exercices from Octave to python/numpy, I have experienced a great deal of frustration. A simple three-line solution in Octave becomes a fifteen-line behemoth that does not even work consistently across different versions of the system.

Re:New IPython release drops Python 2.7 support by lp251 on Thursday April 20, 2017 @07:32PM (#14161834)
Can you give a specific example?
Re:New IPython release drops Python 2.7 support by makmanalp on Thursday April 20, 2017 @01:55PM (#14159102)
I feel for you. Perhaps some of this may help:

It sounds like you're mostly having trouble with OpenCV, which has a horrid API, especially the python version adds another layer of confusion on top of it, and dumping things back and forth from opencv Mat objects to numpy arrays sucks and wastes time. The documentation also is fairly bad. The error messages, like you say, kinda suck. So I can't help you much with that but know that the opencv python bindings fall WAY below the standard of what's considered good. Stuff like simplecv is a bit better but doesn't cover nearly as much as OpenCV does.

Numpy itself is great though, for how little code you often need for a complex, vectorized matrix operation. I've used stuff like Eigen (or even boost matrices or raw BLAS stuff) which I think is way more painful to deal with. For the annoying cruft that any of those bring, the minor speed boost over numpy isn't worth it for me most of the time.

The other thing is, when folks complain about the slowness of python when doing computationally heavy stuff like this, it's often the situation that they have a bunch of vectorized operations, and in the middle somewhere, they stick in something like a regular python for loop, which is orders of magnitude slower. The trick, especially for hot loops, is to just avoid using anything but vectorized operations. In something like C++ of course you're less likely to notice this happening because there is much less overhead, but there'd still be an impact of doing stuff the non-vectorized way anyway.

For profiling, take a look at this: https://www.huyng.com/posts/python-performance-analysis plus the internal cprofile module that does call-graph profiling. It's nothing amazing like vtune or whatever, but it gets the job done.

As far as architecture goes - the relative lack of typing structure in python definitely makes life easier in many ways and cuts down on boilerplate, but it also makes it much easier to shoot yourself in the foot like you say. One thing to keep in mind is that when writing data heavy code there is an additional layer of concerns in play. Stuff like the "shape" of your data. It sounds like if you're running into this, what you want is to make a big diagram / graph of how data is flowing through your code, each stage of computation, and what the data looks like before and after. When you understand this well, it's much easier to reason about the code.

One thing that helps to know is that the style of programming in the python world is a bit different. In C++ land, the instinct is to start with building architecture, and when you inevitably realize that you've misunderstood the problem domain, you do a massive refactor. This usually constitutes large changes in how your code is structured but C++ gives you tools, like strong types, to do this rather easily. With python, unless you're setting of on a massive project, you start with minimal architecture. Write code that does the thing you need. Then, as you find yourself repeating yourself or doing unnecessary things, or dealing with complexity you don't need to know, only then do you start giving structure to your code bit by bit, as you need it. It's a different philosophy that's the result of a different set of functionalities.

In the larger context, I mostly have the opposite experience as you - I can pull out C++ whenever I need it, but I almost never do. The set of tools I have for computation an analysis in python are so much richer. For example, imagine c++ code for reading an excel sheet, and scraping some data off the web, cleaning both, joining them together, running a complex mathematical calculation, and saving a few plots. And I can do this from scratch in half an hour, around 100 lines of code. I also have an interactive shell that I can explore the data and the libraries I have, and I'm not stuck in the code-compile-code-compile loop. The productivity boost is amazing. In contrast, I don't even want to imagine what it would be like to attempt to do this in C++. Python is great glue. Admittedly, you're pushing at the edges of what python is useful for. It's definitely possible (I've written computer vision stuff with python before, and it worked OK), but if you're not making use of any of these benefits of using python, you might as well use C++ and enjoy the speed and strong typing.

Hope this helps your python experience be a bit smoother!

Re:New IPython release drops Python 2.7 support by BeetleB on Thursday April 20, 2017 @02:51PM (#14159634)
While a lot of your points are valid, I'll say I haven't found anything better in the "dynamic" space. It's still better than MATLAB...

Also, do you use pandas, and why not?

Re:New IPython release drops Python 2.7 support by 88e282102ae2e5b on Thursday April 20, 2017 @06:47PM (#14161577)
Does scikit-image have the algorithms you need? If so, I'd highly recommend it for image processing - the API and documentation are well done.
Re:New IPython release drops Python 2.7 support by newen on Friday April 21, 2017 @01:40AM (#14163334)
Try Julia. It's fast and it combines a dynamic language and types very nicely.
Re:New IPython release drops Python 2.7 support by marvy on Thursday April 20, 2017 @03:52PM (#14160214)
Re: speed. Do you suppose pypy might help?
Re:New IPython release drops Python 2.7 support by trentnelson on Thursday April 20, 2017 @03:47PM (#14160170)
Sounds like you need a good mentor.