Data Science Tells This Story About the Global Wine Markets 🍷

πŸ“– Background Many people like to relax or party with a glass of wine. That makes wine an important industry in many countries. Understanding this market is important to the livelihood of many people. For fun, consider the following fictional scenario: 🍷 Story: You work at a multinational consumer goods organization that is considering entering … Read more

How to Normalize a NumPy Matrix

In this blog post, we’ll discuss how to normalize a matrix using the popular Python library NumPy. But first things first: πŸ‘‡ What is Normalization? In mathematics, normalizing refers to making something standardized or regular. Normalization of a matrix is a process of scaling the matrix so that the elements of the matrix have a … Read more

NumPy Array Slicing – A Helpful Guide

Python NumPy array slicing is used to extract parts of data from an array. Array Slicing is often used when working with NumPy. In this article, we will go over the methods of array slicing, from basic to more advanced techniques. We will use the np.array() function to create our array examples. Before practicing any … Read more

How to Write a Hex String as Binary Data & Binary File in Python?

Hex String as Binary Data To convert a hex string such as ‘FF0001AF’ to binary data, use the binascii.unhexlify(hex_str) function that returns the binary data represented by the hexadecimal string. Note that this converts two hex string digits to one byte, i.e., hex string ‘F0’ is converted to the byte representation 11110000, or in binary … Read more

Python Hex String to Big Endian (Bytes/Integer)

What Is Big/Little Endian? Computers perform computations on data that is represented with bytes, i.e., sequences of 0s and 1s. A computer program manipulates data by loading data from memory (RAM, Cache, Disk, SSD), performing computations based on that data, and storing the resulting data back into the memory. A computer program loads and stores … Read more

Format Integer List to Hex String – Six Pythonic Ways

Problem Formulation πŸ’¬ Question: How to create a string of hex digits from a list of integers (0–255) so that each hex digit consists of two digits such as “00”, “01”, …, “fe”, “ff”? Here’s an example input/output pair: In: [0, 1, 2, 3, 255, 254, 253] Out: ‘00010203fffefd’ Method 1: Bytearray The easiest way … Read more

7 Pythonic Ways to Copy a Dictionary

Problem Formulation and Solution Overview This article will show you how to copy a Dictionary in Python 7 different ways. To make it more interesting, we have the following running scenario: Mr. Smith, a High School Math Teacher, has developed an exciting way to grade multiple-choice exams. He has designed a Dictionary with the exam … Read more

Python – Hex String to Bytearray

Problem Formulation Given a string in hexadecimal form: How to convert the hex string to a bytearray object in Python? Here are a few examples: Hex String Bytearray Object ’01’ bytearray(b’\x01′) ’04’ bytearray(b’\x04′) ’08’ bytearray(b’\x08′) ’01 0a’ bytearray(b’\x01\n’) ’01 02 0e 0f 0f’ bytearray(b’\x01\x02\x0e\x0f\x0f’) ‘0f 0f’ bytearray(b’\x0f\x0f’) Hex String to Bytearray using bytearray.fromhex(hex_string) To convert … Read more