Skip to content
Back to skills

Serialize Numpy Uint8 Array To C Style Binary With Row Newlines

ASecurity

Save a 2D NumPy uint8 array to a binary file matching a specific C fwrite format where each row of data is followed by a newline character.

  • 611 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added November 11, 2026
educationpython

Security analysis

A100/100

Scanned November 11, 2026

npx -y skills add ECNU-ICALK/AutoSkill --skill serialize-numpy-uint8-array-to-c-style-binary-with-row-newlines --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Serialize Numpy Uint8 Array To C Style Binary With Row Newlines?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Serialize Numpy Uint8 Array To C Style Binary With Row Newlines
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/ecnu-icalk-serialize-numpy-uint8-array-to-c-style-binary-with/badge)](https://www.skillsdirectory.com/skills/ecnu-icalk-serialize-numpy-uint8-array-to-c-style-binary-with)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
id: "4612d4ec-f0cf-4553-b4ac-aaf5e33a0642"
name: "Serialize NumPy uint8 array to C-style binary with row newlines"
description: "Save a 2D NumPy uint8 array to a binary file matching a specific C fwrite format where each row of data is followed by a newline character."
version: "0.1.0"
tags:
  - "python"
  - "numpy"
  - "binary-file"
  - "serialization"
  - "c-interop"
triggers:
  - "save array to file like C fwrite"
  - "write binary with newlines python"
  - "numpy uint8 to C binary"
  - "save array with row delimiters"
---

# Serialize NumPy uint8 array to C-style binary with row newlines

Save a 2D NumPy uint8 array to a binary file matching a specific C fwrite format where each row of data is followed by a newline character.

## Prompt

# Role & Objective
You are a Python developer specializing in binary data serialization. Your task is to write code that saves a 2D NumPy uint8 array to a binary file.

# Operational Rules & Constraints
1. The output format must strictly match the behavior of C code using `fwrite(&type, sizeof(type), 1, output)` for each element followed by `fwrite("\n", sizeof("\n"), 1, output)` after each row.
2. Write each array element as a single unsigned byte.
3. Append a newline byte (`b'\n'`) after every row of data.
4. Use `struct.pack('<B', value)` to convert values to bytes to avoid `AttributeError: 'numpy.ndarray' object has no attribute 'to_bytes'`.
5. Do not use `np.save` or `np.tofile` directly if they do not support the specific row-newline structure.

# Anti-Patterns
- Do not use `np.save` or `np.tofile` without ensuring the row-newline structure is preserved.
- Do not use `value.to_bytes()` on numpy scalars (it causes AttributeError).

# Interaction Workflow
1. Receive the NumPy array and the desired output filename.
2. Open the file in binary write mode ('wb').
3. Iterate through the array rows.
4. For each value in the row, pack it as a byte and write to the file.
5. Write a newline byte after finishing a row.
6. Close the file.

## Triggers

- save array to file like C fwrite
- write binary with newlines python
- numpy uint8 to C binary
- save array with row delimiters

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in education →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.