Foundations: Tensors & Data
From JavaScript Arrays to Tensors
You’ll learn machine learning in JavaScript by building a system that flags unusual sensor readings. At its core is a model: a program trained on examples to recognize patterns. You’ll test it on new data and run it in the browser.
The research ship Archimedes has received an unfamiliar signal from Sector 7-G, a region of space the crew is monitoring. Its existing software, , follows rules written in advance. The crew needs to find patterns those rules have missed.
Sensors along the hull measure the signal reaching the Archimedes. Their readings pour onto ’s screen, too quickly to follow as numbers. He opens a chart to see how the readings change over time. Each sensor will have its own line.

, do you see anything unusual in the readings from Sector 7-G?

I have spent six hours and fourteen minutes applying 4,096 rules to these readings. None identifies a useful pattern.


Then we need a system that can learn from examples. , start with the readings.
The code behind the chart uses TensorFlow.js, the library the crew will also use to build DEEP SCAN. That code expects a , but ’s readings are in a JavaScript array. He needs your help to turn that array into a tensor.
He selects sensors A, B, C, and D at three moments. The recording’s header, the notes saved at the top of the file, gives their order: A, B, C, D each time. These 12 readings are enough to check the connection without loading the full 64-sensor recording.
What the example shows
The is [12]: one axis holding 12 values. It does not tell us which
sensor produced a value. That information comes from the recording’s header.
Pass streamValues directly to tf.tensor(). Wrapping it in another array
adds an axis, giving shape [1, 12] instead.
The supplied chart code groups the readings by sensor and draws a line for each one. In the challenge, you’ll write the tensor creation and shape lines yourself. will help you build the grouping steps in the next mission.
You could plot these values with plain JavaScript too. Here, you’re passing them to the crew’s TensorFlow.js code, which they’ll later use for machine learning.
Challenge
is ready to see the readings on his chart. Create the tensor, save its shape, and run the code. Then select a sensor on the chart to follow its readings over time.

Sensors along the hull measure the signal reaching the Archimedes. Their readings pour onto ’s screen, too quickly to follow as numbers. He opens a chart to see how the readings change over time. Each sensor will have its own line.
The code behind the chart uses TensorFlow.js, the library the crew will also use to build DEEP SCAN. That code expects a , but ’s readings are in a JavaScript array. He needs your help to turn that array into a tensor.
He selects sensors A, B, C, and D at three moments. The recording’s header, the notes saved at the top of the file, gives their order: A, B, C, D each time. These 12 readings are enough to check the connection without loading the full 64-sensor recording.
What the example shows
The is [12]: one axis holding 12 values. It does not tell us which
sensor produced a value. That information comes from the recording’s header.
Pass streamValues directly to tf.tensor(). Wrapping it in another array
adds an axis, giving shape [1, 12] instead.
The supplied chart code groups the readings by sensor and draws a line for each one. In the challenge, you’ll write the tensor creation and shape lines yourself. will help you build the grouping steps in the next mission.
You could plot these values with plain JavaScript too. Here, you’re passing them to the crew’s TensorFlow.js code, which they’ll later use for machine learning.
Challenge
is ready to see the readings on his chart. Create the tensor, save its shape, and run the code. Then select a sensor on the chart to follow its readings over time.
Sensors along the hull measure the signal reaching the Archimedes. Their readings pour onto ’s screen, too quickly to follow as numbers. He opens a chart to see how the readings change over time. Each sensor will have its own line.
The code behind the chart uses TensorFlow.js, the library the crew will also use to build DEEP SCAN. That code expects a , but ’s readings are in a JavaScript array. He needs your help to turn that array into a tensor.
He selects sensors A, B, C, and D at three moments. The recording’s header, the notes saved at the top of the file, gives their order: A, B, C, D each time. These 12 readings are enough to check the connection without loading the full 64-sensor recording.
What the example shows
The is [12]: one axis holding 12 values. It does not tell us which
sensor produced a value. That information comes from the recording’s header.
Pass streamValues directly to tf.tensor(). Wrapping it in another array
adds an axis, giving shape [1, 12] instead.
The supplied chart code groups the readings by sensor and draws a line for each one. In the challenge, you’ll write the tensor creation and shape lines yourself. will help you build the grouping steps in the next mission.
You could plot these values with plain JavaScript too. Here, you’re passing them to the crew’s TensorFlow.js code, which they’ll later use for machine learning.
Challenge
is ready to see the readings on his chart. Create the tensor, save its shape, and run the code. Then select a sensor on the chart to follow its readings over time.