Why does pyserial read as b'number' - file

I want to save those values in a file.txt, when the program saves them, it saves b'number', I'd like to plot those values but I can't with b'number' I just want number saved

You need to transform your input data into numbers because in your case pyserial is sending binary data, not prepared numeric. Also, byte order matters, you should specify whether it is 'big-endian', 'little-endian', 'native' etc.
If you are using Python 3.x, your job can be done this way:
values = [int.from_bytes(binary_number, 'little') for binary_number in binary_data]
And plot your values.
Hope this helps.

Related

How to save a tensor

I have a dataset of 1000 items. I normalize the data before I train the model against it.
I would now like to use the model to make predictions. However, from what I understand, I need to normalize the inputs that I will feed to the model for which I need the predictions for. In order to carry this out, I would need the mean and std calculated at the time of training.
While I am able to print it to the console, how does one "save" it - to be used later? I am trying to understand the procedure here on how to save the mean and std used at the time of normalization of the training data - so that I can use it again at the time of making predictions.
I determined that we could first get the array representation of the tensor through:
// tensor here is the tensor variable that contains the tensor
const tensorAsArray = tensor.arraySync()
and then, we save it to a file like any other string
fs.writeFile(myFilePath, JSON.stringify(tensorAsArray), 'utf-8')
To read it back and use it as a tensor, we would do the opposite:
const tensorAsArray = JSON.parse(fs.readFile(myFilePath, 'utf-8'))
const tensor = tf.tensor(tensorAsArray)
This allowed me to save the mean and std for use later.

Working with CSV imge data to perform CNN in Julia - format problem

I am trying to make a convolusional neural network on MNIST sign language dataset. It is provided in a CSV format where each row is one picture and there are 784 columns refering to a single pixel (the pictures have a size 28x28).
My problem is that in order to perform the algorithm I need to transpose my data to a different format, the same as is the format of a built-in ML dataset fashion MNIST, which is:
Array{Array{ColorTypes.Gray{FixedPointNumbers.Normed{UInt8,8}},2},1}
I would like to end up with the following format, where my data is joined with the encoded labels:
Array{Tuple{Array{Float32,4},Flux.OneHotMatrix{Array{Flux.OneHotVector,1}}},1}
I was trying to use reshape function to convert it to a 4-dimensional array, but all I get is:
7172×28×28×1 Array{Float64,4}
My labels are in the following (correct) format:
25×7172 Flux.OneHotMatrix{Array{Flux.OneHotVector,1}}
I understand that somehow the proper data format is an array in an array while my data is a simple array with 4 dimensions, but I can't figure out how to change that.
I am new to Julia and some of the code I am using has been written by someone else.

Setting one CSV as an array to compare data from another CSV

I am new to Python and am over complicating the coding on a project so I am starting with much smaller data sets in order to learn the process. My boss is having me compare two CSV files. The first CSV only contains the data 1,2,3,4,5,6 all in a single column. He wants me to set this CSV file as an array so I can compare the second CSV against it. The second CSV contains the data 3,5,6 all in a single column. The code should result in a print out of 1,2,4 as it is the only data not found in both CSV files.
I originally tried to write a code to import both CSV files and compare data without setting it as an array but this did not work so the first CSV file needs to be set as an array. The problem is I am not sure exactly how to do this with an array. This is what I have so far, any help anyone could give me would be greatly appreciated. I have been working on this project for a week now and am at a total loss, even with this simplified form.
import csv
temp_list = []
with open('1.csv','rb') as csvfile:
reader = csv.reader(csvfile, delimiter=',')
for row in reader:
In terms of psuedo-code, what you need to do here is import both csv files into two separate arrays, Array A and Array B for example.
Now what you need to do is compare each index position in one array, to each index position in the other array.
You need to create a nested loop, where the outer loop will choose an index position in A and then inner loop chooses a position in B.
After you check one index in A with each position in B, and no positions are the same, I suggest adding this value into a third array, C. You can check which positions are the same by using a boolean flag. When your code is done, C will have any values that don't exist in both A and B.
I suggest following these tutorials to learn more about python syntax:
https://www.w3schools.com/python/
Good luck

Adding numbers from 3 different CSV columns

I am newer to programming and I am trying to figure out how I can add all of the numbers from the B column together and all of the C column together and the D column together with those variables named x y and z respectively. I have been searching everywhere for an answer. All I have gotten is to read the first line of the csv file.
This is a screenshot of part of the CSV file:
Once you've read it in, you need to somehow split it up into actual columns. Check this function, that should help.
strtok()
Then you need to store it in some kind of array. Then index which elements in the array you want, and process them by using a cumulative sum. This might require a while loop until you've reached the last line of the file.
I will leave the actual code to you, but this should get you going.

Reading large Excel array into MATLAB

So I have a huge excel file with 210 columns from(A all the way to CK)-Each of these columns have 80000-300000 values.I want to read this into a MATLAB array.I have two problems:
1.Is there any way that I can loop through the letters iteratively(from A to CK)?
2.When I try to read the file as a whole it says no storage-but I am able to create a matrix of ones of size-300000*210....So Im a bit puzzled and dont know what to do..??
Thanks!!
Save in the .csv format from EXCEL, then use load -ascii in matlab.
You can loop through the Excel column with the option xlRange of xlsread (doc).
And both the output num = xlsread(...) and [num,txt,raw] = xlsread(...) duplicate the information being read in several variables (type edit xlsread in the command window).

Resources