Postingan lainnya
Numpy ke csv file
halo, saya mau bertanya. Bagaimana cara menulis ke file csv dari hasil output numpy loop ?
import glob
import cv2
from os import listdir
from os.path import isfile, join
import os
import numpy as np
from sklearn.utils.validation import check_array
import csv
import pandas as pd
def find_mode(np_array) :
vals,counts = np.unique(np_array, return_counts=True)
index = np.argmax(counts)
return(vals[index])
folder = ("C:/Users/ROG FLOW/Desktop/Untuk SIDANG TA/Sudah Aman/testbikincsv/folderdatacitra/*.jpg")
for file in glob.glob(folder):
image = cv2.imread(file)
rows = image.shape[0]
cols = image.shape[1]
middlex = cols/2
middley = rows/2
middle = [middlex,middley]
titikawalx = middlex - 10
titikawaly = middley - 10
titikakhirx = middlex + 10
titikakhiry = middley + 10
crop = image[int(titikawaly):int(titikakhiry), int(titikawalx):int(titikakhirx)]
c = cv2.cvtColor(crop, cv2.COLOR_BGR2HSV)
H,S,V = cv2.split(c)
Modus_citra = find_mode(H) # tinggal masukan ke csv
1 Jawaban:
<div>Kode kamu sulit dibaca. <br>Berikut contoh dasar convert array Numpy ke CSV<br><br></div><pre>
import necessary libraries
import pandas as pd import numpy as np
create a dummy array
arr = np.arange(1,11).reshape(2,5)
display the array
print(arr)
convert array into dataframe
DF = pd.DataFrame(arr)
save the dataframe as a csv file
DF.to_csv("data1.csv")</pre><div><br>Sumber <a href="https://www.geeksforgeeks.org/convert-a-numpy-array-into-a-csv-file/">https://www.geeksforgeeks.org/convert-a-numpy-array-into-a-csv-file/</a></div>