Products
  • Wolfram|One

    The definitive Wolfram Language and notebook experience

  • Mathematica

    The original technical computing environment

  • Wolfram Notebook Assistant + LLM Kit

    All-in-one AI assistance for your Wolfram experience

  • System Modeler
  • Wolfram Player
  • Finance Platform
  • Wolfram Engine
  • Enterprise Private Cloud
  • Application Server
  • Wolfram|Alpha Notebook Edition
  • Wolfram Cloud App
  • Wolfram Player App

More mobile apps

Core Technologies of Wolfram Products

  • Wolfram Language
  • Computable Data
  • Wolfram Notebooks
  • AI & Linguistic Understanding

Deployment Options

  • Wolfram Cloud
  • wolframscript
  • Wolfram Engine Community Edition
  • Wolfram LLM API
  • WSTPServer
  • Wolfram|Alpha APIs

From the Community

  • Function Repository
  • Community Paclet Repository
  • Example Repository
  • Neural Net Repository
  • Prompt Repository
  • Wolfram Demonstrations
  • Data Repository
  • Group & Organizational Licensing
  • All Products
Consulting & Solutions

We deliver solutions for the AI era—combining symbolic computation, data-driven insights and deep technical expertise

  • Data & Computational Intelligence
  • Model-Based Design
  • Algorithm Development
  • Wolfram|Alpha for Business
  • Blockchain Technology
  • Education Technology
  • Quantum Computation

WolframConsulting.com

Wolfram Solutions

  • Data Science
  • Artificial Intelligence
  • Biosciences
  • Healthcare Intelligence
  • Sustainable Energy
  • Control Systems
  • Enterprise Wolfram|Alpha
  • Blockchain Labs

More Wolfram Solutions

Wolfram Solutions For Education

  • Research Universities
  • Colleges & Teaching Universities
  • Junior & Community Colleges
  • High Schools
  • Educational Technology
  • Computer-Based Math

More Solutions for Education

  • Contact Us
Learning & Support

Get Started

  • Wolfram Language Introduction
  • Fast Intro for Programmers
  • Fast Intro for Math Students
  • Wolfram Language Documentation

More Learning

  • Highlighted Core Areas
  • Demonstrations
  • YouTube
  • Daily Study Groups
  • Wolfram Schools and Programs
  • Books

Grow Your Skills

  • Wolfram U

    Courses in computing, science, life and more

  • Community

    Learn, solve problems and share ideas.

  • Blog

    News, views and insights from Wolfram

  • Resources for

    Software Developers

Tech Support

  • Contact Us
  • Support FAQs
  • Support FAQs
  • Contact Us
Company
  • About Wolfram
  • Career Center
  • All Sites & Resources
  • Connect & Follow
  • Contact Us

Work with Us

  • Student Ambassador Initiative
  • Wolfram for Startups
  • Student Opportunities
  • Jobs Using Wolfram Language

Educational Programs for Adults

  • Summer School
  • Winter School

Educational Programs for Youth

  • Middle School Camp
  • High School Research Program
  • Computational Adventures

Read

  • Stephen Wolfram's Writings
  • Wolfram Blog
  • Wolfram Tech | Books
  • Wolfram Media
  • Complex Systems

Educational Resources

  • Wolfram MathWorld
  • Wolfram in STEM/STEAM
  • Wolfram Challenges
  • Wolfram Problem Generator

Wolfram Initiatives

  • Wolfram Science
  • Wolfram Foundation
  • History of Mathematics Project

Events

  • Stephen Wolfram Livestreams
  • Online & In-Person Events
  • Contact Us
  • Connect & Follow
Wolfram|Alpha
  • Your Account
  • User Portal
  • Wolfram Cloud
  • Products
    • Wolfram|One
    • Mathematica
    • Wolfram Notebook Assistant + LLM Kit
    • System Modeler
    • Wolfram Player
    • Finance Platform
    • Wolfram|Alpha Notebook Edition
    • Wolfram Engine
    • Enterprise Private Cloud
    • Application Server
    • Wolfram Cloud App
    • Wolfram Player App

    More mobile apps

    • Core Technologies
      • Wolfram Language
      • Computable Data
      • Wolfram Notebooks
      • AI & Linguistic Understanding
    • Deployment Options
      • Wolfram Cloud
      • wolframscript
      • Wolfram Engine Community Edition
      • Wolfram LLM API
      • WSTPServer
      • Wolfram|Alpha APIs
    • From the Community
      • Function Repository
      • Community Paclet Repository
      • Example Repository
      • Neural Net Repository
      • Prompt Repository
      • Wolfram Demonstrations
      • Data Repository
    • Group & Organizational Licensing
    • All Products
  • Consulting & Solutions

    We deliver solutions for the AI era—combining symbolic computation, data-driven insights and deep technical expertise

    WolframConsulting.com

    Wolfram Solutions

    • Data Science
    • Artificial Intelligence
    • Biosciences
    • Healthcare Intelligence
    • Sustainable Energy
    • Control Systems
    • Enterprise Wolfram|Alpha
    • Blockchain Labs

    More Wolfram Solutions

    Wolfram Solutions For Education

    • Research Universities
    • Colleges & Teaching Universities
    • Junior & Community Colleges
    • High Schools
    • Educational Technology
    • Computer-Based Math

    More Solutions for Education

    • Contact Us
  • Learning & Support

    Get Started

    • Wolfram Language Introduction
    • Fast Intro for Programmers
    • Fast Intro for Math Students
    • Wolfram Language Documentation

    Grow Your Skills

    • Wolfram U

      Courses in computing, science, life and more

    • Community

      Learn, solve problems and share ideas.

    • Blog

      News, views and insights from Wolfram

    • Resources for

      Software Developers
    • Tech Support
      • Contact Us
      • Support FAQs
    • More Learning
      • Highlighted Core Areas
      • Demonstrations
      • YouTube
      • Daily Study Groups
      • Wolfram Schools and Programs
      • Books
    • Support FAQs
    • Contact Us
  • Company
    • About Wolfram
    • Career Center
    • All Sites & Resources
    • Connect & Follow
    • Contact Us

    Work with Us

    • Student Ambassador Initiative
    • Wolfram for Startups
    • Student Opportunities
    • Jobs Using Wolfram Language

    Educational Programs for Adults

    • Summer School
    • Winter School

    Educational Programs for Youth

    • Middle School Camp
    • High School Research Program
    • Computational Adventures

    Read

    • Stephen Wolfram's Writings
    • Wolfram Blog
    • Wolfram Tech | Books
    • Wolfram Media
    • Complex Systems
    • Educational Resources
      • Wolfram MathWorld
      • Wolfram in STEM/STEAM
      • Wolfram Challenges
      • Wolfram Problem Generator
    • Wolfram Initiatives
      • Wolfram Science
      • Wolfram Foundation
      • History of Mathematics Project
    • Events
      • Stephen Wolfram Livestreams
      • Online & In-Person Events
    • Contact Us
    • Connect & Follow
  • Wolfram|Alpha
  • Wolfram Cloud
  • Your Account
  • User Portal
Wolfram Language & System Documentation Center
ThreadingLayer
  • See Also
    • FunctionLayer
    • ElementwiseLayer
    • TotalLayer
    • AggregationLayer
    • NetArrayLayer
    • RandomArrayLayer
    • NetChain
    • NetGraph
    • NetTrain
    • SoftmaxLayer
    • DropoutLayer
  • Related Guides
    • Neural Network Layers
    • Neural Networks
    • Neural Network Construction & Properties
  • Tech Notes
    • Neural Networks in the Wolfram Language
    • See Also
      • FunctionLayer
      • ElementwiseLayer
      • TotalLayer
      • AggregationLayer
      • NetArrayLayer
      • RandomArrayLayer
      • NetChain
      • NetGraph
      • NetTrain
      • SoftmaxLayer
      • DropoutLayer
    • Related Guides
      • Neural Network Layers
      • Neural Networks
      • Neural Network Construction & Properties
    • Tech Notes
      • Neural Networks in the Wolfram Language

ThreadingLayer[f]

represents a net layer that takes several input arrays and applies a function f to corresponding array elements.

ThreadingLayer[f,bspec]

allows array shapes to be conformed according to broadcasting specification bspec.

Details and Options
Details and Options Details and Options
Examples  
Basic Examples  
Scope  
Applications  
Possible Issues  
See Also
Tech Notes
Related Guides
History
Cite this Page
BUILT-IN SYMBOL
  • See Also
    • FunctionLayer
    • ElementwiseLayer
    • TotalLayer
    • AggregationLayer
    • NetArrayLayer
    • RandomArrayLayer
    • NetChain
    • NetGraph
    • NetTrain
    • SoftmaxLayer
    • DropoutLayer
  • Related Guides
    • Neural Network Layers
    • Neural Networks
    • Neural Network Construction & Properties
  • Tech Notes
    • Neural Networks in the Wolfram Language
    • See Also
      • FunctionLayer
      • ElementwiseLayer
      • TotalLayer
      • AggregationLayer
      • NetArrayLayer
      • RandomArrayLayer
      • NetChain
      • NetGraph
      • NetTrain
      • SoftmaxLayer
      • DropoutLayer
    • Related Guides
      • Neural Network Layers
      • Neural Networks
      • Neural Network Construction & Properties
    • Tech Notes
      • Neural Networks in the Wolfram Language

ThreadingLayer

ThreadingLayer[f]

represents a net layer that takes several input arrays and applies a function f to corresponding array elements.

ThreadingLayer[f,bspec]

allows array shapes to be conformed according to broadcasting specification bspec.

Details and Options

  • ThreadingLayer is typically used inside NetGraph.
  • In ThreadingLayer[f], the function f can be any one of the following: Plus, Subtract, Times, Divide, Power, Surd, Min, Max, Clip, Mod, ArcTan, Erf.
  • In general, f can be any object that when applied to two arguments gives any combination of Plus, Subtract, etc. together with numbers; all functions supported by ElementwiseLayer; and some logical operations using If, And, Or, Which, Piecewise, Equal, Greater, GreaterEqual, Less, LessEqual, Unequal.
  • The function f can also contain expressions of the form "name"[input], where name is one of the named functions ("ELU", "SELU", "SoftSign", etc.) accepted by ElementwiseLayer.
  • In ThreadingLayer[f,bspec], smaller arrays are implicitly replicated before applying f to match dimensions of larger arrays. The following settings can be given for bspec:
  • Noneno replication
    Automaticreplicate along axis of size 1 (default)
    ninsert dimension(s) with the right size at level n if needed
    -ncount from the end
    {spec1,spec2,…}use specific broadcasting settings for the respective input arrays
  • Option InputPorts can be used to specify the number, names or shapes of input ports. If InputPorts is not specified, the number of ports and their shapes are inferred from NetChain or NetGraph connectivity.
  • Besides input ports, ThreadingLayer exposes the following port for use in NetGraph etc.:
  • "Output"an array
  • Within a NetGraph, a ThreadingLayer can be connected using a single edge of the form {src1,src2,…}threadlayer, where threadlayer is the name or index of the ThreadingLayer, or as multiple separate edges given in the corresponding order, as src1threadlayer,src2threadlayer,…,srcnthreadlayer.
  • If no names are explicitly given for input ports, ThreadingLayer[f,…] exposes input ports named "Input1", "Input2", etc.
  • ThreadingLayer[Function[… #Name1 … #Name2 …], …] exposes input ports named "Name1", "Name2", etc.
  • ThreadingLayer[f,None] forces all input arrays to have the same shape, and the output has this shape. ThreadingLayer[f,Automatic] forces all input arrays to have the same rank, and the respective shapes must be the same or equal to 1. ThreadingLayer[Plus,-1] automatically broadcasts inputs like Plus by inserting dimensions at the deepest level.
  • ThreadingLayer[…][{in1,in2,…}] explicitly computes the output from applying the layer, which is effectively given by f[in1,in2,…].
  • When given NumericArray as inputs, the output will be a NumericArray.
  • Options[ThreadingLayer] gives the list of default options to construct the layer. Options[ThreadingLayer[…]] gives the list of default options to evaluate the layer on some data.
  • Information[ThreadingLayer[…]] gives a report about the layer.
  • Information[ThreadingLayer[…],prop] gives the value of the property prop of ThreadingLayer[…]. Possible properties are the same as for NetGraph.

Examples

open all close all

Basic Examples  (6)

Create a ThreadingLayer using Times as the function to be threaded:

Apply the layer to a pair of inputs:

Create a ThreadingLayer that sums arrays with different dimensions, broadcasting the smallest arrays on the first dimensions:

Apply the layer to a pair of inputs:

Create a ThreadingLayer that sums arrays with different dimensions, broadcasting the smallest arrays on the last dimensions:

Apply the layer to a pair of inputs:

Use ThreadingLayer in a NetGraph:

Apply the net to two vectors:

Create a NetGraph that computes the outer sum of two arrays with ThreadingLayer:

Apply the outer sum to a pair of inputs:

The names of input ports can be specified using option "Inputs":

The names of input ports can be specified directly within the function of ThreadingLayer:

Apply the layer to an association of arrays:

Scope  (2)

Create a ThreadingLayer that takes a specific number of inputs:

Apply it to data:

Create a ThreadingLayer that uses a custom transformation to compute a spherical Gaussian:

Evaluate the layer on two input vectors to get a vector of outputs:

Plot the output of the layer:

Applications  (1)

Define a hinge loss using a ThreadingLayer:

Create a net that computes the hinge loss with a margin of 2:

When the target is within distance 2 of the input, the loss is zero:

The loss increases linearly beyond a distance of 2:

Plot the loss as a function of input for a fixed target of 2:

Perform linear regression using the hinge loss:

Plot the solution:

Compare the solutions obtained using the hinge loss, mean absolute and mean squared error:

Possible Issues  (3)

ThreadingLayer cannot accept symbolic inputs:

Certain choices of f can produce failures for inputs outside their domain:

Some pure functions are not supported:

See Also

FunctionLayer  ElementwiseLayer  TotalLayer  AggregationLayer  NetArrayLayer  RandomArrayLayer  NetChain  NetGraph  NetTrain  SoftmaxLayer  DropoutLayer

Tech Notes

    ▪
  • Neural Networks in the Wolfram Language

Related Guides

    ▪
  • Neural Network Layers
  • ▪
  • Neural Networks
  • ▪
  • Neural Network Construction & Properties

History

Introduced in 2017 (11.1) | Updated in 2018 (11.3) ▪ 2020 (12.1) ▪ 2020 (12.2) ▪ 2021 (13.0)

Wolfram Research (2017), ThreadingLayer, Wolfram Language function, https://reference.wolfram.com/language/ref/ThreadingLayer.html (updated 2021).

Text

Wolfram Research (2017), ThreadingLayer, Wolfram Language function, https://reference.wolfram.com/language/ref/ThreadingLayer.html (updated 2021).

CMS

Wolfram Language. 2017. "ThreadingLayer." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2021. https://reference.wolfram.com/language/ref/ThreadingLayer.html.

APA

Wolfram Language. (2017). ThreadingLayer. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ThreadingLayer.html

BibTeX

@misc{reference.wolfram_2025_threadinglayer, author="Wolfram Research", title="{ThreadingLayer}", year="2021", howpublished="\url{https://reference.wolfram.com/language/ref/ThreadingLayer.html}", note=[Accessed: 01-December-2025]}

BibLaTeX

@online{reference.wolfram_2025_threadinglayer, organization={Wolfram Research}, title={ThreadingLayer}, year={2021}, url={https://reference.wolfram.com/language/ref/ThreadingLayer.html}, note=[Accessed: 01-December-2025]}

Top
Introduction for Programmers
Introductory Book
Wolfram Function Repository | Wolfram Data Repository | Wolfram Data Drop | Wolfram Language Products
Top
  • Products
  • Wolfram|One
  • Mathematica
  • Notebook Assistant + LLM Kit
  • System Modeler

  • Wolfram|Alpha Notebook Edition
  • Wolfram|Alpha Pro
  • Mobile Apps

  • Wolfram Player
  • Wolfram Engine

  • Volume & Site Licensing
  • Server Deployment Options
  • Consulting
  • Wolfram Consulting
  • Repositories
  • Data Repository
  • Function Repository
  • Community Paclet Repository
  • Neural Net Repository
  • Prompt Repository

  • Wolfram Language Example Repository
  • Notebook Archive
  • Wolfram GitHub
  • Learning
  • Wolfram U
  • Wolfram Language Documentation
  • Webinars & Training
  • Educational Programs

  • Wolfram Language Introduction
  • Fast Introduction for Programmers
  • Fast Introduction for Math Students
  • Books

  • Wolfram Community
  • Wolfram Blog
  • Public Resources
  • Wolfram|Alpha
  • Wolfram Problem Generator
  • Wolfram Challenges

  • Computer-Based Math
  • Computational Thinking
  • Computational Adventures

  • Demonstrations Project
  • Wolfram Data Drop
  • MathWorld
  • Wolfram Science
  • Wolfram Media Publishing
  • Customer Resources
  • Store
  • Product Downloads
  • User Portal
  • Your Account
  • Organization Access

  • Support FAQ
  • Contact Support
  • Company
  • About Wolfram
  • Careers
  • Contact
  • Events
Wolfram Community Wolfram Blog
Legal & Privacy Policy
WolframAlpha.com | WolframCloud.com
© 2025 Wolfram
© 2025 Wolfram | Legal & Privacy Policy |
English