Python property() — What You Always Wanted to Know But Never Dared to Ask

Object-orientation is great way to encapsulate data in your application. This minimizes complexity and adheres to good software engineering principles. However, attributes in Python can be easily accessed from the outside—they’re not really encapsulated. That’s one of the reason the property() built-in function exists: it allows you to truly encapsulate data with the means of … Read more

Python Get Milliseconds

In this article we are going to look at how we can see time in milliseconds,  i.e. one thousandth (1000th) of a second, using Python. This could be for pure curiosity, benchmarking code or to get  a very, very accurate time of day –  whatever the reason, the focus of the article is how to … Read more

Python vars() Function

Python’s built-in vars() function returns the __dict__ attribute of an object—a dictionary containing the object’s changeable attributes. Without argument, it returns the local symbol table similar to locals(). Python’s built-in vars() function returns a dictionary of name: value mappings of all the names defined in the local scope or the scope of the optional object … Read more

Top 10 Go Cheat Sheets

Hey Finxters! It is time to do yet another cheat sheet! This time we are going to step away from Python (only for a moment!) and discuss GoLang. Unlike Python, which is dynamic- GoLang is a procedural and statically typed language similar to the C programming language. It is currently one of the trending programming … Read more

How to Calculate the Weighted Average of a Numpy Array in Python?

Numpy Weighted Average np.average(array, axis=0, weights=[0.1,0.1,0.8])

Problem Formulation: How to calculate the weighted average of the elements in a NumPy array? Definition weighted average: Each array element has an associated weight. The weighted average is the sum of all array elements, properly weighted, divided by the sum of all weights. Here’s the problem exemplified: Quick solution: Before we discuss the solution … Read more