Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Server Side Programming Articles
Page 122 of 2109
Top Hat and Black Hat Transform using OpenCV Python
Top Hat and Black Hat Transforms are morphological operations used for feature extraction and enhancement in image processing. These operations help extract small details from images by analyzing structural differences between the original image and its morphological transformations. Top Hat Transform extracts bright small elements by computing the difference between the original image and its opening (top hat = image - opening). It highlights small bright features that are smaller than the structuring element. Black Hat Transform extracts dark small elements by computing the difference between the image's closing and the original image (black hat = closing - ...
Read MoreConversion between binary, hexadecimal and decimal numbers using Coden module
The coden is a Python library developed by Tanmay Earappa for handling secret codes and number base conversions. This module provides convenient functions to convert between binary, hexadecimal, and decimal number systems. Installation Install the coden module using pip − pip install coden Key Conversion Functions The coden module provides the following conversion functions − hex_to_bin(): Converts hexadecimal to binary hex_to_int(): Converts hexadecimal to decimal bin_to_hex(): Converts binary to hexadecimal bin_to_int(): Converts binary to decimal int_to_bin(): Converts decimal to binary int_to_hex(): Converts decimal to hexadecimal Hexadecimal to Binary Conversion ...
Read MoreConvert a nested for loop to a map equivalent in Python
Nested for loops execute repetitive code blocks, where an inner loop runs completely for each iteration of the outer loop. Python's map() function provides a functional programming approach to achieve similar results by applying functions to iterables. Understanding Nested For Loops A nested for loop structure contains one loop inside another ? for x in sequence: for y in sequence: # inner loop code # outer loop code Map Function Syntax map(function, iterable) Where: function: Function applied ...
Read MoreConvert \"unknown format\" strings to datetime objects in Python
Dates can be in many formats like "2009/05/13 19:19:30", "May 13 2009 07:19PM", and "2009-05-13 19:19". Python provides several approaches to convert these unknown format strings into datetime objects using the datetime and dateutil modules. A Python datetime object contains complete information about date and time including year, month, day, hours, minutes, seconds, and time zones. This article shows how to convert unknown format date strings to datetime objects. Input-Output Example Here's what we want to achieve ? Input string (unknown format): 20050607T090650 Output Datetime object: 2005-06-07 09:06:50 Data type: Using datetime.strptime() ...
Read MorePython Program to insert multiple elements into the array from the specified index
An array is a collection of homogeneous data elements stored in an organized way. Each data element in the array is identified by an index value. In Python, we can insert multiple elements at a specific index position using various approaches. Arrays in Python Python does not have a native array data structure, so we use the list data structure as an alternative ? # Python list example my_list = [10, 4, 11, 76, 99] print(my_list) [10, 4, 11, 76, 99] We can also use the NumPy module to work with ...
Read MorePython Program to find the distinct elements from two arrays
In programming, an array is a data structure used to store a collection of homogeneous data elements. Each element is identified by a key or index value. In Python, we use lists to represent arrays. Finding distinct elements from two arrays means identifying unique elements that exist in one array but not in the other − this is also known as the symmetric difference. Input Output Scenarios Let's look at example inputs and expected outputs ? Input arrays: A = [1, 2, 3, 4, 5] B = [5, 2, 6, 3, 9] Output array: [1, ...
Read MorePython Program to get the first given number of items from the array
An array is a data structure of a set of items with the same data type, and each element is identified by an index. In Python, we can get the first few items from an array using slicing syntax array[:n]. Arrays in Python Python does not have its own data structure to represent an array. However, we can use the list data structure as an alternative to the arrays. Here we will use list as an array − numbers = [10, 4, 11, 76, 99] print(numbers) [10, 4, 11, 76, 99] ...
Read MorePython Program to get the last item from the array
An array is a data structure used to store a collection of homogeneous data elements. Each element in the array is identified by an index value or key. Arrays in Python Python doesn't have a built-in data structure to represent arrays, but it has a built-in array module for working with arrays. We can also use the NumPy package. An array defined by the array module is − import array arr = array.array('i', [1, 2, 3, 4]) print(arr) array('i', [1, 2, 3, 4]) A NumPy array defined by the NumPy ...
Read MoreHow to Automate an Excel Sheet in Python?
Excel automation with Python allows you to manipulate spreadsheets programmatically, saving time and reducing manual errors. Python offers several powerful libraries for Excel automation: openpyxl for direct Excel file manipulation, pandas for data analysis operations, and xlwings for advanced Excel integration. Method 1: Using openpyxl Library The openpyxl library provides direct access to Excel files, allowing you to read, write, and modify spreadsheets cell by cell. Installation pip install openpyxl Example Let's create and manipulate an Excel file that adds bonus calculations to employee salaries − import openpyxl as xl ...
Read MoreGet the day from a date in Pandas
Pandas provides several methods to extract the day name from dates. Whether you're working with single dates or multiple date strings, you can use dt.dayofweek, dt.day_name(), or dt.strftime() to get day information in different formats. Using dt.dayofweek with Manual Mapping The dt.dayofweek property returns numeric values (0-6) for days, which you can map to day names ? import pandas as pd # Create a date range dates = pd.date_range(start='2022-01-01', end='2022-01-07') # Create a DataFrame with the dates df = pd.DataFrame({'date': dates}) # Add a column with the day of the week as numbers ...
Read More