generated from cvxgrp/simulator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
38 additions
and
1,170 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# -*- coding: utf-8 -*- | ||
import json | ||
from collections.abc import Iterable | ||
|
||
import numpy as np | ||
from numpyencoder import NumpyEncoder | ||
|
||
|
||
def read_json(json_file): | ||
"""Read a json file and return a generator of key-value pairs""" | ||
with open(json_file, "r") as f: | ||
json_data = json.load(f) | ||
for name, data in json_data.items(): | ||
if isinstance(data, Iterable): | ||
yield name, np.asarray(data) | ||
else: | ||
yield name, data | ||
|
||
|
||
def write_json(json_file, data): | ||
"""Write a json file with the data""" | ||
with open(json_file, "w") as f: | ||
json.dump(data, f, cls=NumpyEncoder) |
Oops, something went wrong.