BinarySerialize[expr]
任意の式 expr のバイナリ表現をByteArrayオブジェクトとして与える.
BinarySerialize
BinarySerialize[expr]
任意の式 expr のバイナリ表現をByteArrayオブジェクトとして与える.
詳細とオプション
- BinarySerializeには次のオプションが使える.
-
Method Automatic 使用する直列化メソッドの詳細 PerformanceGoal Automatic パフォーマンスのどの面を最適化するか - PerformanceGoalの可能な設定には次がある.
-
"Speed" 直列化シードおよび非直列化シードの最適化 "Size" 直列化された出力の小ささについて最適化 Automatic 直列化の方法を自動的に選択する - Methodの可能な設定には次がある.
-
{typespec1enc1,…} 特定のタイプの符号化を指定する Automatic データに基づいて符号化を自動的に選択する - 次は,typespeci の可能な形式である.
-
"PackedArrayIntegerType" 整数のパックアレー "PackedArrayRealType" 実数値のパックアレー "PackedArrayComplexType" 複素数値のパックアレー - "PackedArrayIntegerType"の可能な設定には,"Integer8","Integer16","Integer32","Integer64"(64バイトのシステムのみ)がある.
- "PackedArrayRealType"の可能な設定には"Real32"と"Real64"がある.
- "PackedArrayComplexType"の可能な設定には,"Complex64"と"Complex128"がある.
- デフォルトの符号化指定 enciはAutomaticで,この場合はBinarySerializeが与えられたデータに適合するタイプを使用する.
- BinarySerializeはWXF形式を使う.
- BinaryDeserializeはBinarySerializeの逆関数である.
例題
すべて開く すべて閉じる例 (2)
スコープ (7)
BinarySerializeを記号式に適用する:
BinarySerialize[f[Sin[g[x]]]]BinarySerialize[[image]]直列化された形のサイズは式のバイト数とほぼ等しい点に注意のこと:
ByteCount[[image]]BinarySerializeは効率的に機械サイズ整数を保存する:
BinarySerialize[2 ^ 7 - 1]BinarySerialize[2 ^ 15 - 1]BinarySerialize[2 ^ 31 - 1]BinarySerializeは,効率的に機械実数を保存する:
BinarySerialize[N[1234 / 5678]]BinarySerialize[N[1234 / 5678, 16]]BinarySerializeは,効率的に数列を保存する:
str = FromCharacterCode[RandomInteger[{0, 2 ^ 15}, 1000]];ByteCount[str]BinarySerialize[str]BinarySerializeはByteArrayをサポートする:
BinarySerialize[ByteArray[RandomInteger[255, 1000]]]BinarySerializeはパックアレーをサポートする:
ints = RandomInteger[2 ^ ($SystemWordLength - 2), 1000];
reals = RandomReal[1, 1000];
complexes = RandomComplex[{0, 1 + I}, 1000];ByteCount /@ {ints, reals, complexes}BinarySerialize /@ {ints, reals, complexes}オプション (4)
Method (3)
integers = ConstantArray[2 ^ 14, 3];デフォルトで,BinarySerializeはデータに適合する最小の整数タイプを使用する:
BinarySerialize[integers]BinarySerialize[integers, Method -> "PackedArrayIntegerType" -> "Integer32"]reals = RandomReal[1, 3]real64 = BinarySerialize[reals]機械浮動整数を使ってこのパックアレーを直列化する(より小さい出力の精度を犠牲にする):
real32 = BinarySerialize[reals, Method -> "PackedArrayRealType" -> "Real32"]complexes = RandomComplex[1 + I, 3]BinarySerialize[complexes]BinarySerialize[complexes, Method -> {"PackedArrayComplexType" -> "Complex64"}]PerformanceGoal (1)
Datasetを直列化する:
data = ExampleData[{"NetworkGraph", "AstrophysicsCollaborations"}];uncompressed = BinarySerialize[data]PerformanceGoalを"Size"に設定して同じDatasetを直列化する:
compressed = BinarySerialize[data, PerformanceGoal -> "Size"]BinaryDeserialize[uncompressed] == BinaryDeserialize[compressed]アプリケーション (1)
bin = BinarySerialize[NetTrain[NetGraph[{LinearLayer[1], LinearLayer[3], LinearLayer[3], LinearLayer["Real"]}, {1 -> 2 -> 3 -> 4}, "Input" -> "Real"], {.1 -> .07, .25 -> .24, .3 -> .32, .5 -> .5}, MaxTrainingRounds -> 1000]]file = CreateFile[];ow = OpenWrite[file, BinaryFormat -> True]BinaryWrite[ow, bin]Close[ow];nettrained = BinaryDeserialize[ByteArray[BinaryReadList[file, "Byte"]]]Plot[nettrained[x], {x, 0, 5}]特性と関係 (4)
PerformanceGoal->"Speed"を使うと速くなるが,大きい出力が生成される:
data = Range[10 ^ 6];BinarySerialize[data, PerformanceGoal -> "Speed"]//AbsoluteTimingPerformanceGoal->"Size"を使った方が遅くなるが,出力は小さい:
BinarySerialize[data, PerformanceGoal -> "Size"]//AbsoluteTimingBinarySerializeは,文字列をUTF-8で符号化する:
bytes = BinarySerialize["→ hello there ←"]ByteArrayToString[bytes, "UTF-8"]BinaryDeserializeはBinarySerializeの逆関数である:
BinaryDeserialize[BinarySerialize[x]] === xDumpSaveはシンボルに付けられた定義をファイルに保存する:
f[x_] := x ^ 2mx = FileNameJoin[{$TemporaryDirectory, "f.mx"}];
DumpSave[mx, f];Clear[f];
restored = Get[mx];
DeleteFile[mx];
{restored, f[x]}BinarySerializeは,BinaryDeserializeで回復可能な入力式だけを保存する:
BinarySerialize[f];
Clear[f];
restored = BinaryDeserialize[%%];
{restored, f[x]}考えられる問題 (2)
小さい式については,PerformanceGoal->"Size"はより小さい出力を生成しないかもしれない:
BinarySerialize[{1, 2, 3}, PerformanceGoal -> "Size"]BinarySerialize[{1, 2, 3}]Methodパラメータの"PackedArrayIntegerType"はデータと互換のものを選ばなければならない:
BinarySerialize[ConstantArray[2 ^ 17, 3], Method -> {"PackedArrayIntegerType" -> "Integer16"}]BinarySerialize[ConstantArray[2 ^ 17, 3], Method -> {"PackedArrayIntegerType" -> "Integer32"}]Automaticに設定すると,常にデータにフィットしたサイズが使われる:
BinarySerialize[ConstantArray[2 ^ 17, 3], Method -> {"PackedArrayIntegerType" -> Automatic}]関連項目
BinaryDeserialize DumpSave Compress ExportByteArray ByteArray BaseEncode ByteArrayToString StringToByteArray Export FullForm InputForm BinaryWrite
コンパイルタイプ: PackedArray
形式: WXF
Function Repository: BinarySerializeWithDefinitions
テクニカルノート
-
▪
- WXF形式の説明
関連するガイド
テキスト
Wolfram Research (2017), BinarySerialize, Wolfram言語関数, https://reference.wolfram.com/language/ref/BinarySerialize.html (2018年に更新).
CMS
Wolfram Language. 2017. "BinarySerialize." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2018. https://reference.wolfram.com/language/ref/BinarySerialize.html.
APA
Wolfram Language. (2017). BinarySerialize. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/BinarySerialize.html
BibTeX
@misc{reference.wolfram_2026_binaryserialize, author="Wolfram Research", title="{BinarySerialize}", year="2018", howpublished="\url{https://reference.wolfram.com/language/ref/BinarySerialize.html}", note=[Accessed: 10-September-2026]}
BibLaTeX
@online{reference.wolfram_2026_binaryserialize, organization={Wolfram Research}, title={BinarySerialize}, year={2018}, url={https://reference.wolfram.com/language/ref/BinarySerialize.html}, note=[Accessed: 10-September-2026]}