Sunday, 30 August 2026

๐Ÿš€ Day 98/150 – reduce() Function in Python

 



๐Ÿš€ Day 98/150 – reduce() Function in Python

The reduce() function is used to repeatedly apply a function to the elements of an iterable until a single value is produced. Unlike map() and filter(), reduce() returns one final result instead of another iterable.

The reduce() function is available in Python's functools module.

Syntax:

from functools import reduce 
reduce(function, iterable)

In this post, we'll explore four common examples of using the reduce() function in Python.


Method 1 – Using reduce() with a Normal Function

Find the sum of all numbers in a list.

from functools import reduce def add(x, y): return x + y numbers = [1, 2, 3, 4, 5] result = reduce(add, numbers) print(result)








Output

15

Explanation

  • add() takes two numbers and returns their sum.

  • reduce() repeatedly applies the function to the list.

  • Calculation:

      (1 + 2) = 3

      (3 + 3) = 6

      (6 + 4) = 10

      (10 + 5) = 15
    • The final result is 15.


Method 2 – Using reduce() with a Lambda Function

Find the product of all numbers in a list.

from functools import reduce numbers = [1, 2, 3, 4, 5] result = reduce(lambda x, y: x * y, numbers) print(result)








Output
120

Explanation

  • lambda x, y: x * y multiplies two numbers.

  • reduce() applies the lambda function repeatedly.

  • Calculation:


    (1 × 2) = 2


    (2 × 3) = 6


    (6 × 4) = 24


    (24 × 5) = 120

Method 3 – Find the Maximum Value

Use reduce() to find the largest element in a list.

from functools import reduce numbers = [12, 45, 7, 89, 23] maximum = reduce(lambda x, y: x if x > y else y, numbers) print(maximum)









Output
89

Explanation

  • The lambda function compares two numbers.

  • It returns the larger one each time.

  • After all comparisons, the largest value remains.


Method 4 – Taking User Input

Find the sum of numbers entered by the user.

from functools import reduce numbers = list(map(int, input("Enter numbers separated by spaces: ").split())) result = reduce(lambda x, y: x + y, numbers) print("Sum:", result)













Sample Input
10 20 30 40

Output

Sum: 100

Explanation

  • input() reads the numbers as a string.

  • split() separates them into individual values.

  • map(int, ...) converts each value to an integer.

  • reduce() adds all the numbers and returns a single sum.


Comparison of Methods

MethodBest For
Normal FunctionReusable reduction logic
Lambda FunctionShort and simple operations
Finding MaximumComparing elements
User InputInteractive programs

๐Ÿ”ฅ Key Takeaways

  • reduce() is available in the functools module.

  • It applies a function repeatedly to reduce an iterable to a single value.

  • reduce() works with both normal functions and lambda functions.

  • It is commonly used for operations like sum, product, maximum, and minimum.

  • Unlike map() and filter(), reduce() returns a single result instead of an iterable.

Stay tuned for Day 99 of the #150DaysOfPython series! ๐Ÿš€

๐Ÿš€ Day 97/150 – Filter() Function in Python

 

๐Ÿš€ Day 97/150 – filter() Function in Python

The filter() function is a built-in Python function used to select elements from an iterable based on a condition. It returns only those elements for which the given function evaluates to True.

Syntax:

filter(function, iterable)

In this post, we'll explore four common examples of using the filter() function in Python.


Method 1 – Using filter() with a Normal Function

Filter even numbers from a list using a normal function.

def is_even(num): return num % 2 == 0 numbers = [1, 2, 3, 4, 5, 6] result = list(filter(is_even, numbers)) print(result)







Output

[2, 4, 6]

Explanation

  • is_even() returns True if a number is even.

  • filter() applies this function to every element in the list.

  • Only the elements for which the function returns True are kept.

  • list() converts the filter object into a list.


Method 2 – Using filter() with a Lambda Function

Use a lambda function to write the filtering logic in a single line.

numbers = [10, 15, 20, 25, 30] result = list(filter(lambda x: x > 20, numbers)) print(result)





Output
[25, 30]


Explanation
  • lambda x: x > 20 checks whether each number is greater than 20.

  • filter() keeps only the numbers that satisfy the condition.

  • The result is converted into a list.


Method 3 – Filtering Strings

Filter words whose length is greater than 5.

words = ["Python", "Java", "Programming", "Code"] result = list(filter(lambda word: len(word) > 5, words)) print(result)









Output

['Python', 'Programming']

Explanation

  • len(word) > 5 checks the length of each word.

  • filter() keeps only the words with more than 5 characters.

  • This method is useful when working with text data.


Method 4 – Taking User Input

Filter even numbers entered by the user.

numbers = list(map(int, input("Enter numbers separated by spaces: ").split())) result = list(filter(lambda x: x % 2 == 0, numbers)) print("Even numbers:", result)







Sample Input
10 15 20 25 30

Output

Even numbers: [10, 20, 30]

Explanation

  • input() reads the numbers as a string.

  • split() separates them into a list.

  • map(int, ...) converts each value to an integer.

  • filter() selects only the even numbers.


Comparison of Methods

MethodBest For
Normal FunctionReusable filtering logic
Lambda FunctionShort and simple conditions
String FilteringFiltering text data
User InputInteractive programs

๐Ÿ”ฅ Key Takeaways

  • filter() selects elements that satisfy a condition.

  • It returns a filter object, which is usually converted to a list using list().

  • filter() works with both normal functions and lambda functions.

  • It is commonly used to filter numbers, strings, and other collections.

  • filter() makes code shorter and more readable than writing equivalent loops.

Stay tuned for Day 98 of the #150DaysOfPython series! ๐Ÿš€

What Mathematical Introduction to Deep Learning: Methods, Implementations, and TheoryBlogging Has Taught Me (Free PDF)

 

Deep Learning is often introduced through practical frameworks and ready-to-use models, but understanding its mathematical foundations provides a much deeper view of how neural networks actually work. Mathematical Introduction to Deep Learning: Methods, Implementations, and Theory by Arnulf Jentzen, Benno Kuckuck, and Philippe von Wurstemberger presents deep learning from this mathematical perspective. The book combines theory, algorithms, implementation, and analysis, with Python source code provided alongside the material.

The work is intended both for learners who are new to deep learning and for practitioners who want a stronger mathematical understanding of the methods they use.

Download the PDF for free: https://arxiv.org/pdf/2310.20360

Understanding Artificial Neural Networks

At its foundation, deep learning uses artificial neural networks (ANNs) to approximate relationships, functions, and quantities from data.

Mathematically, neural networks can be viewed as compositions of affine transformations and nonlinear activation functions. The depth of a network is related to how many such transformations are composed together.

This perspective turns neural networks from simply being software architectures into mathematical objects that can be analyzed rigorously.

Different Neural Network Architectures

The book develops several important neural network architectures, including:

  • Fully connected feedforward networks
  • Convolutional neural networks
  • Residual networks
  • Recurrent neural networks
  • LSTM networks
  • Autoencoders
  • Transformers
  • Graph neural networks
  • Neural operators

These architectures demonstrate how the basic idea of neural networks can be adapted to different types of data and computational problems.

Activation Functions

Activation functions introduce nonlinearity into neural networks. Without suitable nonlinear transformations, compositions of linear operations would remain fundamentally limited in the functions they could represent.

The book discusses a broad range of activation functions, including ReLU, Softplus, GELU, logistic, Swish, hyperbolic tangent, ELU, Softmax, and others.

Understanding activation functions mathematically is important for analyzing both the expressive capabilities and optimization behavior of neural networks.

The Mathematics of Neural Network Calculus

A central part of the theoretical foundation is the mathematical treatment of neural network operations.

The book examines how networks can be composed, parallelized, scaled, added, and represented in different forms. This provides a formal framework for reasoning about increasingly complicated architectures.

Neural Networks as Function Approximators

One of the fundamental questions in deep learning is:

How well can a neural network approximate a desired function?

The book explores approximation theory beginning with one-dimensional functions and extending toward multidimensional functions.

This provides a mathematical explanation for why neural networks can represent complicated relationships and how approximation quality can depend on network architecture.

Optimization and Deep Learning

Training a neural network can be viewed as an optimization problem.

The objective is generally to find network parameters that minimize an appropriate loss or objective function. Because modern networks may contain very large numbers of parameters, efficient optimization methods are essential.

The book therefore dedicates a major section to optimization methods used in deep learning.

Gradient Flow

Gradient flow provides a continuous-time mathematical perspective on optimization.

It helps develop intuition for how optimization procedures move through the parameter space toward better solutions. The book studies gradient-flow ordinary differential equations and their relationship to optimization.

This creates an important connection between deep learning optimization and differential equations.

Gradient Descent

Gradient Descent is one of the fundamental optimization techniques used for training neural networks.

The mathematical treatment considers deterministic gradient descent and examines its connection to continuous gradient-flow dynamics. This perspective helps explain convergence behavior and optimization error.

Stochastic Gradient Descent

Large datasets make full-batch optimization computationally expensive. Stochastic Gradient Descent (SGD) addresses this by using stochastic information during optimization.

SGD is one of the most important practical methods in modern machine learning, and the book examines both its mathematical foundations and theoretical behavior.

Backpropagation

Backpropagation is the primary mechanism used to efficiently calculate gradients through neural networks.

The book derives backpropagation mathematically rather than treating it as a framework-specific operation. This provides a deeper understanding of how information about the loss travels backward through the network during training.

Loss Functions

Loss functions measure how well a model performs relative to its objective.

The book discusses several important loss functions, including absolute error, mean squared error, Huber loss, cross-entropy, and Kullback–Leibler divergence.

Understanding loss functions is important because they determine what the optimization process attempts to improve.

Generalization

A model can perform well on training data without necessarily performing well on unseen data.

This leads to the concept of generalization error, which measures the difference between performance on observed training information and performance on the broader underlying data distribution.

The book dedicates an entire section to probabilistic and strong generalization error estimates.

Approximation, Optimization, and Generalization

A deeper mathematical understanding of deep learning requires considering several different sources of error.

The book connects:

Approximation Error → Optimization Error → Generalization Error

Approximation concerns the ability of the neural network architecture to represent the desired relationship. Optimization concerns how accurately the training procedure finds suitable parameters. Generalization concerns how well the resulting model performs beyond the observed training data.

Together, these perspectives provide a more complete framework for analyzing deep learning systems.

Batch Normalization and Initialization

Training neural networks can be affected by the scale and distribution of internal representations as well as by the starting values of model parameters.

The book examines batch normalization and optimization through different random initializations, connecting these practical techniques with mathematical analysis.

Deep Learning for Differential Equations

Deep learning is not limited to conventional prediction and classification problems.

Neural networks can also be used to approximately solve partial differential equations (PDEs). The book explores this direction through approaches including:

  • Physics-informed neural networks
  • Deep Galerkin methods
  • Deep Kolmogorov methods

This connects deep learning with numerical analysis, applied mathematics, and scientific computing.

Python Implementations

The theoretical material is accompanied by Python source code. The authors provide code through a public repository and the arXiv source associated with the book.

This combination of mathematical theory and implementation is particularly useful because it allows theoretical concepts to be connected with computational practice.

Why Mathematical Foundations Matter

Deep learning frameworks make it possible to build complex models without manually implementing every mathematical operation. However, abstraction can sometimes hide what is actually happening inside the model.

Mathematical foundations provide a way to understand:

  • Why neural networks can approximate complex functions
  • How training algorithms update parameters
  • Why optimization can succeed or fail
  • How approximation errors arise
  • Why models may generalize or overfit
  • How neural networks can be analyzed theoretically

This knowledge becomes especially valuable when moving beyond standard applications toward research and advanced model development.

Download the PDF for free: https://arxiv.org/pdf/2310.20360

Conclusion

Mathematical Introduction to Deep Learning: Methods, Implementations, and Theory presents deep learning as a combination of mathematics, optimization, computation, and approximation theory.

The work moves from neural network architectures and calculus to approximation theory, gradient-based optimization, backpropagation, generalization, and applications to partial differential equations.

Its central value lies in connecting the practical world of deep learning with the mathematical principles underneath it. Rather than viewing neural networks simply as models that can be trained with software libraries, the book provides a framework for understanding why these models work, how they are optimized, how their errors can be analyzed, and where their mathematical foundations lead.

Python Coding Challenge - Question with Answer (ID 300826)

 



Explanation:

1. Create the Range
x = range(10, 0, -3)

Here, range() takes three arguments:

range(start, stop, step)

So:

Start = 10
Stop = 0
Step = -3

2. Understand the Negative Step

Because the step is -3, Python moves backward by 3 each time.

Starting from 10:

10 → 7 → 4 → 1

Python stops before reaching 0.

So x effectively contains:

10, 7, 4, 1

3. sum(x)
sum(x)

The sum() function adds all values in the range:

10 + 7 + 4 + 1

Calculate:

10 + 7 = 17
17 + 4 = 21
21 + 1 = 22

Therefore:

sum(x) = 22

4. print() Displays the Result
print(sum(x))

Python prints:

✅ Final Output
22

Book: 100 Python Automation Projects for Smart Developers

Mathematics in the age of AI (Free PDF)



Artificial Intelligence is beginning to change the way mathematical research is approached. Modern AI systems are increasingly capable of assisting with mathematical reasoning, problem solving, proof development, and other research-level tasks. “Mathematics in the Age of AI”, an essay by mathematician Terence Tao, examines how the mathematical community might respond to this technological shift. The essay is based on a public lecture delivered at the 2026 International Congress of Mathematicians.

Rather than focusing primarily on whether AI will become capable of advanced mathematics, the paper considers a deeper question: What are the actual goals and values of mathematical research when AI can increasingly perform parts of the mathematical process?

Download the pdf for free: https://arxiv.org/abs/2608.16753

AI and Mathematical Research

AI has the potential to influence many stages of mathematical research. It can assist researchers with exploring ideas, investigating problems, organizing information, and developing possible approaches to difficult questions.

This creates a significant change in the traditional relationship between mathematicians and computational tools. Instead of using computers mainly for calculation, researchers may increasingly interact with systems capable of performing more sophisticated reasoning.

The Purpose of Mathematics

A central theme of the essay is that mathematics should not be defined only by the problems it solves.

Mathematical research also involves understanding, discovery, creativity, explanation, communication, and the development of new perspectives. These broader goals become particularly important when AI systems become capable of solving increasingly difficult mathematical problems.

The arrival of powerful AI therefore encourages mathematicians to reconsider what makes mathematical activity valuable.

Problem Solving and Mathematical Understanding

Problem solving provides an important case study in the discussion.

If AI systems eventually become capable of solving many research-level problems, the value of mathematics cannot depend entirely on humans being the fastest or most effective problem solvers.

Instead, mathematical understanding may become increasingly important. Knowing why a result matters, how different ideas connect, and what broader concepts emerge from a solution can remain valuable even when the computational work is assisted by AI.

Human Creativity in Mathematics

Mathematical creativity involves more than manipulating symbols or following established procedures.

Researchers choose problems, formulate questions, identify useful concepts, develop intuition, and decide which directions are worth pursuing.

AI may increasingly contribute to these activities, but the broader question is how humans should interact with such systems while maintaining meaningful intellectual participation in mathematical research.

AI as a Mathematical Collaborator

The development of advanced AI may lead to a new form of collaboration between mathematicians and intelligent computational systems.

Instead of treating AI purely as a calculator or automated solver, researchers may use it as a tool for exploration and idea generation.

This could change how mathematical research is organized, with humans focusing more heavily on high-level direction, interpretation, verification, and conceptual understanding.

Verification and Trust

As AI-generated mathematical reasoning becomes more sophisticated, verification becomes increasingly important.

Mathematical results require rigorous justification. A convincing explanation or apparently correct argument is not sufficient without appropriate validation.

This creates an important role for mathematical expertise: researchers must be able to evaluate AI-generated arguments, understand their assumptions, and determine whether the conclusions genuinely follow.

The Changing Role of Mathematicians

The increasing capabilities of AI may change what mathematicians spend their time doing.

Routine calculations and certain technical tasks may become increasingly automated. Researchers could therefore devote more attention to:

  • Formulating important questions
  • Developing mathematical intuition
  • Understanding concepts
  • Connecting different areas
  • Evaluating AI-generated ideas
  • Communicating mathematical insights

This does not necessarily reduce the importance of mathematicians. Instead, it may shift the emphasis toward higher-level intellectual activities.

Mathematical Education

AI also raises important questions for mathematics education.

If students have access to systems capable of solving mathematical problems instantly, traditional approaches to assignments and assessment may become less effective.

Education may need to place greater emphasis on understanding, reasoning, problem formulation, explanation, and mathematical communication, rather than simply producing final answers.

The Future of Mathematical Discovery

AI could potentially accelerate mathematical discovery by exploring large numbers of possibilities and assisting researchers with difficult problems.

However, mathematical progress is not measured only by the number of problems solved. New concepts, connections, perspectives, and forms of understanding can be equally important.

The future of mathematics may therefore involve a combination of automated problem-solving capabilities and human-driven conceptual development.

Rethinking the Values of Mathematics

The paper ultimately encourages a broader discussion about what mathematicians value.

If AI eventually becomes highly capable at solving mathematical problems, mathematics may need to place greater emphasis on the aspects of research that go beyond obtaining solutions.

Understanding why a problem is interesting, discovering useful concepts, communicating ideas, and building a shared mathematical culture may become increasingly important.

Download the pdf for free: https://arxiv.org/abs/2608.16753

Conclusion

“Mathematics in the Age of AI” explores how artificial intelligence may transform mathematical research and challenges the mathematical community to think beyond the question of what AI can accomplish. The essay instead asks what mathematics is ultimately trying to achieve and what values should guide mathematical research in an AI-driven future.

The emergence of advanced AI does not necessarily mean the end of human mathematics. Instead, it may encourage a shift from mathematics as primarily problem solving toward a broader vision centered on understanding, creativity, discovery, communication, and intellectual exploration.


PaperBanana: Automating Academic Illustration for AI Scientists (free PDF)

 


Academic research often depends on clear diagrams, methodology figures, and statistical illustrations to communicate complex ideas. However, creating publication-quality figures can be time-consuming and usually requires both technical understanding and design skills.

PaperBanana is an agentic framework proposed to automate this part of the research workflow. The system uses vision-language models and image-generation models to create academic illustrations from research content, with the goal of producing figures that are accurate, readable, concise, and visually suitable for scientific publications.

Download the PDF for free: https://arxiv.org/abs/2601.23265

The Need for Automated Academic Illustration

Research papers frequently contain complex methodologies, architectures, workflows, and experimental results. Converting these concepts into clear illustrations requires considerable manual effort.

For AI researchers in particular, the growing speed of research makes automated assistance for scientific communication increasingly valuable. PaperBanana addresses this problem by treating illustration generation as a structured research task rather than simply generating an image from a text prompt.

PaperBanana Framework

PaperBanana uses multiple specialized agents to coordinate different stages of illustration creation.

The framework involves processes for:

  • Retrieving relevant references
  • Planning the content of an illustration
  • Planning visual style
  • Generating the illustration
  • Reviewing the generated result
  • Refining the output through self-critique

This agentic structure allows different stages of the generation process to work together rather than relying on a single image-generation step.

Reference Retrieval

Reference retrieval helps the system understand how academic illustrations should represent particular concepts.

By using relevant research material as a reference, the framework can better align generated figures with the information and visual conventions associated with scientific communication.

This is particularly important for methodology diagrams, where preserving the relationship between components is more important than simply producing an attractive image.

Content and Style Planning

PaperBanana separates the planning of what should be shown from how it should look.

Content planning focuses on representing the important ideas and relationships from the research material. Style planning focuses on the visual organization and presentation of those ideas.

This separation helps create illustrations that are both informative and visually structured.

Iterative Self-Critique

A major component of the framework is iterative refinement.

Instead of accepting the first generated illustration, PaperBanana uses a self-critique process to evaluate the output and improve it.

This approach is important because academic illustrations need more than visual quality. They must also preserve the meaning of the research and communicate information clearly.

PaperBananaBench

The researchers introduce PaperBananaBench, an evaluation benchmark containing 292 methodology-diagram test cases derived from NeurIPS 2025 publications.

The benchmark covers different research domains and illustration styles, providing a way to evaluate automated academic illustration systems systematically.

Evaluation Criteria

PaperBanana evaluates generated illustrations across several important dimensions, including:

Faithfulness

The illustration should accurately represent the information and methodology being communicated.

Conciseness

The figure should communicate the important information without unnecessary complexity.

Readability

Labels, components, and relationships should be understandable to the viewer.

Aesthetics

The final illustration should have a professional and visually coherent appearance suitable for academic communication.

According to the paper, PaperBanana outperforms the evaluated baseline methods across these dimensions.

Statistical Plot Generation

The framework is not limited to methodology diagrams. The researchers also show that the approach can be extended to generate high-quality statistical plots.

This suggests that automated scientific illustration could potentially support multiple stages of research communication, from explaining methodologies to presenting experimental findings.

Importance for AI Research

PaperBanana highlights a broader direction in AI research: AI systems that assist not only with scientific discovery but also with scientific communication.

As autonomous and semi-autonomous AI scientists become more capable, automatically producing understandable figures can reduce the manual effort required to communicate research results.

Future of AI-Assisted Research

The idea behind PaperBanana represents a shift toward more complete AI research workflows. Instead of AI systems focusing only on writing, coding, or experimentation, future systems may also assist with visual explanation, documentation, presentation, and publication preparation.

This can make scientific workflows more efficient while allowing researchers to spend more time on ideas, experimentation, and interpretation.

Download the PDF for free: https://arxiv.org/abs/2601.23265

Conclusion

PaperBanana presents an agentic approach to automating academic illustration using vision-language and image-generation models. Its workflow combines reference retrieval, content planning, style planning, image generation, and iterative self-critique to produce publication-oriented illustrations.

The introduction of PaperBananaBench also provides a structured way to evaluate the quality of automatically generated academic figures. Overall, the work demonstrates how AI can move beyond generating text and code toward automating visual scientific communication, an important direction for the future of AI-assisted research.

Popular Posts

Categories

100 Python Programs for Beginner (119) AI (342) Android (25) AngularJS (1) Api (7) Assembly Language (2) aws (31) Azure (12) BI (10) book (1) Books (351) Bootcamp (14) C (78) C# (12) C++ (83) cloud (1) Course (90) Coursera (303) Cybersecurity (36) data (10) Data Analysis (46) Data Analytics (31) data management (16) Data Science (425) Data Strucures (18) Deep Learning (218) Django (16) Downloads (3) edx (21) Engineering (15) Euron (30) Events (7) Excel (24) Finance (13) flask (4) flutter (1) FPL (17) Generative AI (77) Git (13) Google (54) Hadoop (3) HTML Quiz (1) HTML&CSS (48) IBM (43) IoT (3) IS (25) Java (99) Leet Code (4) Machine Learning (396) Meta (24) MICHIGAN (5) microsoft (13) Nvidia (8) Pandas (16) PHP (20) Projects (34) Python (1364) Python Coding Challenge (1229) Python Library (1) Python Mathematics (15) Python Mistakes (51) Python Quiz (615) Python Tips (108) Questions (3) R (72) React (7) Scripting (3) security (4) Selenium Webdriver (4) Software (21) SQL (55) Udemy (20) UX Research (1) web application (11) Web development (9) web scraping (3)

Followers

Python Coding for Kids ( Free Demo for Everyone)