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
Programming Articles
Page 130 of 2547
Write a program in Python to replace all the 0's with 5 in a given number
Given an integer N, the task is to replace all the 0's that appear in the number with '5'. However, leading zeros are ignored as they don't affect the number's value. For example, if N = 1007, the output should be 1557. Example Cases Input-1 − N = 1007 Output − 1557 Explanation − The given number has 2 zeros which when replaced by '5' results in the output as 1557. Input-2 − N = 105 Output − 155 Explanation − ...
Read MoreMajority Element in Python
The majority element is an element that appears more than half the times in an array. For example, in an array of size 8, a majority element must appear at least 5 times. Python provides several approaches to find the majority element efficiently. Problem Definition Given an array of integers, find the element that appears more than n/2 times, where n is the array size. If no such element exists, return -1. Example 1 ? Input: [2, 1, 1, 2, 2, 2] Output: 2 Explanation: Element 2 appears 4 times out of 6, which is ...
Read MoreWrite a program in Python to count the number of digits in a given number N
Let's suppose we have given a number N. The task is to find the total number of digits present in the number. For example, Input-1 − N = 891452 Output − 6 Explanation − Since the given number 891452 contains 6 digits, we will return '6' in this case. Input-2 − N = 74515 Output − 5 Explanation − Since the given number 74515 contains 5 digits, we will print the output as 5. The Approach Used to Solve This Problem ...
Read MoreCount Good Meals in Python
A good meal contains exactly two different food items with a sum of deliciousness equal to a power of two. You can pick any two different foods to make a good meal. Given an array of integers arr where arr[i] is the deliciousness of the ith item of food, we need to return the number of different good meals you can make from this list. Examples Input-1 − arr = [1, 3, 5, 7, 9] Output − 4 Explanation − The good meals are (1, 3), (1, 7), (3, ...
Read MoreBirthday Paradox in Python
The Birthday Paradox is a famous probability problem that asks: "How many people need to be in a room before there's a 50% chance that two people share the same birthday?" The counterintuitive answer is just 23 people! This paradox demonstrates how our intuition about probability can be misleading. Understanding the Mathematics The probability that two people have different birthdays is 364/365, which equals (1 - 1/365) in a non-leap year. For multiple people, the probability that all have different birthdays is: P(different) = 1 × (1-1/365) × (1-2/365) × (1-3/365) × ... Therefore, ...
Read MoreHow to set window size using phantomjs and selenium webdriver in Python?
We can set window size using PhantomJS and Selenium webdriver in Python. PhantomJS is a headless browser that allows automated testing without displaying a GUI. To work with PhantomJS, we create a driver object of the webdriver.PhantomJS class and pass the path to the phantomjs.exe driver file as a parameter. To set the window size, we use the set_window_size method and pass the width and height dimensions as parameters. We can also retrieve the current window size using the get_window_size method. Syntax driver.set_window_size(width, height) print(driver.get_window_size()) Parameters width − The desired window width ...
Read MoreHow can Keras be used to remove a layer from the model using Python?
TensorFlow is a machine learning framework provided by Google. It is an open-source framework used with Python to implement algorithms, deep learning applications, and much more. It is used in research and for production purposes. Keras was developed as part of research for the project ONEIROS (Open-ended Neuro-Electronic Intelligent Robot Operating System). Keras is a deep learning API written in Python. It is a high-level API that provides a productive interface to help solve machine learning problems. Keras is highly scalable and comes with cross-platform abilities. This means Keras can be run on TPU or clusters of GPUs. ...
Read MoreHow can Bokeh be used to create step line plot in Python?
Bokeh is a Python package that helps in data visualization. It is an open source project. Bokeh renders its plots using HTML and JavaScript, making it ideal for web-based dashboards and interactive applications. Bokeh can be easily used in conjunction with NumPy, Pandas, and other Python packages. It can be used to produce interactive plots, dashboards, and real-time data visualizations. Installation You can install Bokeh using pip or conda ? pip3 install bokeh Or using Anaconda ? conda install bokeh Creating Step Line Plots The step() function in ...
Read MoreExplain how a sequential model (Dense Layer) be built in Tensorflow using Python
TensorFlow is a machine learning framework provided by Google. It is an open-source framework used with Python to implement algorithms, deep learning applications, and much more. It is used for both research and production purposes. The 'tensorflow' package can be installed on Windows using the below command: pip install tensorflow The layers API is part of the Keras API. Keras is a high-level deep learning API written in Python that runs on top of TensorFlow. It provides essential abstractions and building blocks for developing machine learning solutions with a productive interface. Keras is already ...
Read MoreWhen should a sequential model be used with Tensorflow in Python? Give an example
A sequential model in TensorFlow is used when you have a simple stack of layers where each layer has exactly one input and one output tensor. It's the most straightforward way to build neural networks for linear data flow. When to Use Sequential Models Sequential models are appropriate when: Each layer has exactly one input and one output tensor Layers are arranged in a linear sequence You have a simple feedforward architecture Sequential models are not appropriate when: Your model has multiple inputs or multiple outputs Layers need to be shared between ...
Read More