FastAPI

main.py from fastapi import FastAPIfrom pydantic import BaseModelfrom typing import Union app = FastAPI()items = [“one”,”two”,”three”,”four”] class Item(BaseModel):name: strprice: floatdescription: Union[str, None] = None @app.get(“/”)def read_root():return {“message”: “Hello world!!”} @app.get(“/items”)def read_items(skip: int = 0, limit: int = 10):return {“items”: items[skip : skip + limit]} @app.post(“/items/”)def create_item(item: Item):print(f”データを登録します: {item.name}, {item.price}, {item.description}”)return item client.py import requests res = requests.get(“http://127.0.0.1:8000/items/”) res = requests.post(“http://127.0.0.1:8000/items/”,json={“name”:”Tシャツ”, “price”: 2000, “description”: “白Tシャツ”},) print(res.status_code)print(res.text) python -m uvicorn main:app –reload http://127.0.0.1:8000/

データを分割するPythonスクリプト

import numpy as np input_matrix = np.array([     [1, 2, 3, 0],     [4, 5, 6, 1],     [3, 6, 7, 0] ]) rows_to_insert = np.where(input_matrix[:, 3] == 1)[0] for row in reversed(rows_to_insert):     new_row = np.copy(input_matrix[row])     input_matrix = np.insert(input_matrix, row, new_row, axis=0)     input_matrix = np.insert(input_matrix, row + 2, new_row, axis=0)     input_matrix[row , 3] = 0     input_matrix[row + 2, 3] = 0 # 結果を表示 for row in input_matrix:     print(row)