python 3.x – I can't find the error code

Could someone tell me what the error of this code is:

valor_hora = float(input('Valor da hora trabalhada: '))
qtd_horas_trabalhadas = int(input('Quantidade de horas trabalahadas: '))

salario_bruto = valor_hora * qtd_horas_trabalhadas
ir = salario_bruto * 0.11
inss = salario_bruto * 0.08
sindicato = salario_bruto * 0.05
salario_liquido = salario_bruto - (ir + inss + sindicato)

print(f'''+ Salário Bruto : R$ {salario_bruto:.2f}
          - IR (11%) : R$ {ir:2.f}
          - INSS (8%) : R$ {inss:2.f}
          - SINDICATO (5%) : R$ {sindicato:.2f}
          ----------------------------
          = Salário líquido : R${salario_liquido:.2f}''')

Traceability (last call last): print (f & # 39; & # 39; & # 39; + gross salary: R $
{Gross wages} ValueError: Lack of accuracy of the format identifier

python – I have this json file, but I just want to print or access the owner_id or prices data, but all the data contained in the json file

{
    "id": 1,
    "name": "Cargador",
    "code": "12",
    "description": "rerer",
    "unit": "12",
    "visible_to": "3",
    "owner_id": {
        "id": 11321795,
        "name": "SAUL BALDERRAMA PEREZ",
        "email": "1630275@upv.edu.mx",
        "value": 11321795
    },
    "add_time": "2020-01-13 19:18:31",
    "update_time": "2020-01-17 22:52:45",
    "prices": [
        {
            "id": 1,
            "product_id": 1,
            "price": 1000,
            "currency": "MXN",
        }
    ]
},
{
    "id": 2,
    "name": "Caja",
    "code": "123",
    "owner_id": {
        "id": 11321795,
        "name": "SAUL BALDERRAMA PEREZ",
        "email": "1630275@upv.edu.mx",
        "value": 11321795
    },
    "add_time": "2020-01-13 20:52:46",
    "update_time": "2020-01-13 20:52:46",
    "prices": [
        {
            "id": 2,
            "product_id": 2,
            "price": 100,
            "currency": "MXN",
        }
    ]
},

I just want to access the price or owner_id data, but all the data in the file

Example:

"Prices": [
{
"id": 2,
"product_id": 2,
"Price": 100,
"currency": "MXN",
"Cost": 0,
"Overhead": zero
}]

"Prices": [
{
"id": 1,
"product_id": 1,
"Price": 1000,
"currency": "MXN",
"Cost": 0,
"Overhead": zero
}]

python 3.x – data frame. How do I change the margin or the alignment in the display of the data table?

BD

Have a dictionary and present its values ​​in a DataFrame to change the orientation or margin of the result

for example:

If the resulting example looks like this:

A b
Snack lunch
Snack snack

And what I want is that it works like this:

A b
Snack lunch
Snack snack

thank you for your time

python – Random Walk for 500×500 is not efficient enough

For a 500×500 matrix with 50,000 iterations, the calculation would easily take a whole day. How can the computing time be drastically reduced?

Logically, the program is correct.

I tried to create a profile, it didn't tell me much. The while loop is causing the problem? Any suggestions on how to improve the efficiency of my code?

import time
import numpy as np
import random
import matplotlib.pyplot as plt 
from numba import jit, cuda, prange

#from numba import roc
starttime = time.time()
arr = (h,w) = (500,500) #track of height and width of canvas
particles = 50000
sticking_coeff = 0.5
canvas = np.zeros((h, w)).astype(int) #the blank n * n matrix
canvas(h//2,w//2) = 1 #make center element is 1
#// to get the floor value
stick = ()
stick.append((h//2 + 1, w//2))#below 1 
stick.append(((h//2 - 1, w//2)))#above 1 
stick.append((h//2, w//2 + 1))#right of 1 
stick.append((h//2, w//2 - 1))#left of 1 

#@jit(nopython=True, parallel=True)
#@roc.jit(device=True)
#@numba.jit()
@jit(cache=True)
def walk(A, B, canvas):# A: row B: Column
    while True:
        #print('while')
        x = np.random.randint(4)#0: row 1: column
        if x == 0:#forward option
            A += 1
            #print('A+')
        elif x == 1:
            B += 1
            #print('B+')
        elif x == 2:
            A -= 1 #reverse option
            #print('A-')
        else:
            B -= 1
            #print('B-')

        #take care of overflow 
        if A < 0:
            A = 0
            #print('A=0')
        elif B < 0:
            B = 0
            #print('B=0')
        if A >= h:
            A -= 1
            #print('A-1')
        elif B >= w:
            B -= 1
            #print('B-1')

        positi = (A , B)    
        if positi in stick:
            if np.random.rand() < sticking_coeff:
                for site in ((positi(0) + 1, positi(1)),
                            (positi(0) - 1, positi(1)),
                            (positi(0), positi(1) + 1),
                            (positi(0), positi(1) - 1)):
                    if site not in stick:
                        stick.append(site)
                canvas(positi(0) , positi(1)) = 1   
                break  # <-- Also, this is require, I think
            else:
                continue

    return canvas

for i in prange(particles):

        print('particle ',i+1)
        selec = random.sample(set(('A','B','C','D')),1)
        #pos1 = randrange(0, len(arr))
        pos = np.random.randint(0, len(arr))
        print(selec)

        if selec == ('A'):
            #arr(:,0)#first column
            #arr(pos,0) = 1
            walk(pos,0,canvas)

        elif selec == ('B'):
            #arr(:,-1)#last column
            #arr(pos,-1) = 1
            walk(pos,-1,canvas)

        elif selec == ('C'):   
            #arr(0,:)#first row
            #arr(0,pos) =1
            walk(0,pos,canvas)

        else:    
            #arr(-1,:)#last row
            #arr(-1,pos) = 1
            walk(-1,pos,canvas)
plt.matshow(canvas)
plt.savefig("rand_walk.png",dpi=2000)
print('That took {} seconds'.format(time.time() - starttime))
```

PyQT5 – Python 3: Switchable windows

How are you
Well, I basically need a simple example of how to use PyQT5 and Python 3.8 to create two windows that alternately display those windows. If you open the first window with a button and click on it, the current window is hidden and a new window is opened with a button that also hides the second window when the button is clicked and shows the first window that was opened again. first.
I managed to create the first window with the button pressed and hide the current window, and another window with a button appears. So far rest. The problem is that nothing happens when you press the button in this second window. I found some things on the Internet that only go from one window to another without returning to the original window. I've tried setModal, but it's not what I want. I don't want one window to overlap the other.
Could someone help me with this? As long as you do this task, this can be the simplest example. after that the rest is easy.
I appreciate the help.

Load Python modules in Elixir

I have just started Elixir and want to run the Python programs from Elixir. I also created an Elixir project Mix, I have added the required python files in the priv / python3 folder and can run the required python program. The problem, however, is that my Python application first has to load multiple libraries, ML models, and Pandas dataframe. This takes 10-20 seconds. Every time I call the Python function from Elixir, all of these libraries, models and data frames are loaded and it takes much longer to perform a simple function. Is there a way to load all models and data frames into Elixir first and use them when calling Python functions instead of loading them every time?

Let me know if anyone needs more details. Thank you very much.

python – What tools do I need to implement the algorithm on the card?

I want to display Voronoi diagrams on a map.

I would like to know which tools I need for Google Maps and without Google Maps (somehow on a picture of the map)

I've heard of Qgis, Arcgis, and some tools. However, I'm not sure which one I need in R and Python (I know both languages). Do I really need to know GIS libraries if I want to implement an algorithm on a map?

And I would very much appreciate it if you could share a link for this type of course. (Udemy especially)

Attribute error in the chatbot in Python

I'm trying to chatbot with Chatterbot version 1.0.5, but when I try to open it I get an error:

bot.set_trainer(ListTrainer)
AttributeError: 'ChatBot' object has no attribute 'set_trainer'

Here is the code:

from chatterbot.trainers import ListTrainer
from chatterbot import ChatBot
import os

bot=ChatBot('Teste')

bot.set_trainer(ListTrainer) #O erro


for arq in os.listdir('arq'):
    chats=open('arq/' + arq, 'r').readlines()
    bot.train(chats)

while True:
    resq=input('Você: ')

    resp=bot.get_response(resq)
    print('Bot: ' + resp)

Note: The text documents with the conversations are in the file folder, which is in the same folder as the chatbot

I cannot access my folders with python – jupyter notebook

(! (Hello, this is the first time I am posting here, so I hope I uploaded the image well.

What happened is that when I open Jupyter Notebook I don't see my "desktop" folder (where I have my scripts) or "documents" etc. I couldn't solve the problem because I don't know how to do it. I took a screenshot to see how it looks to me.

Thanks in advance) 1) 1

numpy – machine learning of the Python MNIST data set

I am a beginner of machine learning and have struggled with it for a few days and I cannot understand why my neural network is having problems classifying the Mnist record. I checked my math and used the history check, but I can't seem to find the problem.

import pickle as pc
import numpy as np
import matplotlib.pyplot as mb
class MNIST:
#fix: gradient checking maybe not working, maybe backprop not working, symetrical updating, check if copying correctly


    def processImg(self):

        '''
        #slower than pickle file
        inTrset = np.loadtxt("mnist_train.csv", delimiter = ",");
        inTestSet = np.loadtxt("mnist_test.csv", delimiter = ",");
        fullX = np.asfarray(inTrset(:,1:))
        fullY = np.asfarray(inTrset(:, :1))
        '''

        with open("binaryMNIST.pkl", "br") as fh:
            data = pc.load(fh)


        img_dim = 28;
        features = 784;
        m = 60000
        test_m = 10000;

        fullX = (np.asfarray(data(0)))
        bias = np.ones((60000, 1))
        fullX = np.hstack((bias, fullX))

        fullY = np.asfarray(data(1))

        testX = (np.asfarray(data(2)))
        bias2 = np.ones((10000, 1))
        testX = np.hstack((bias2, testX))

        testY = np.asfarray(data(3))

        fullY = fullY.astype(int)
        testY = testY.astype(int)

        iden = np.identity(10, dtype = np.int)
        oneHot = np.zeros((m, 10), dtype = np.int)
        oneHot_T = np.zeros((test_m, 10), dtype = np.int)

        #creates m number of one, zeros vector indicating the class
        for i in range(test_m):
            oneHot_T(i) = iden(testY(i), :)

        for i in range(m):
            oneHot(i) = iden(fullY(i), :)

        trainX = fullX(:40000, :)
        trainY = oneHot(:40000, :)

        valX = np.asfarray(fullX(40000:, :))
        valY = np.asfarray(oneHot(40000:, :))


        self.trainX = trainX
        self.trainY = trainY
        self.valX = valX
        self.valY = valY
        self.testX = testX
        self.oneHot_T = oneHot_T


    def setThetas(self):
        #784 features
        #5 nodes per layer (not including bias)
        #(nodes in previous layer, nodes in next layer)
        #theta1(785, 5) theta2(6, 5) theta3(6, 10)

        #after finishing, do big 3d matrix of theta and vectorize backprop

        params = np.random.rand(4015)
        self.params = params



    def fbProp(self, theta1, theta2, theta3):

        #after calculating a w/sig(), add bias
        m = np.shape(self.trainY)(0)
        z1 = np.array(np.dot(self.trainX, theta1), dtype = np.float64)

        a1 = self.sig(z1)
        bias = np.ones((40000, 1))
        a1 = np.hstack((bias, a1))
        z2 = np.dot(a1, theta2)
        a2 = self.sig(z2)
        a2 = np.hstack((bias, a2))
        z3 = np.dot(a2, theta3)
        hyp = self.sig(z3)

        g3 = 0
        g2 = 0
        g1 = 0

        for i in range(m):
            dOut = hyp(i, :) - self.trainY(i, :)
            d2 = np.dot(np.transpose(dOut), np.transpose(theta3))
            d2 = d2(1:) * self.sigG(z2(i, :))
            d1 = np.dot(d2, np.transpose(theta2))
            d1 = d1(1:) * self.sigG(z1(i, :))

            g3 = g3 + np.dot(np.transpose(np.array(a2(i, :), ndmin = 2)), np.array(dOut, ndmin = 2))
            g2 = g2 + np.dot(np.transpose(np.array(a1(i, :), ndmin = 2)), np.array(d1, ndmin = 2))
            g1 = g1 + np.dot(np.transpose(np.array(self.trainX(i, :), ndmin = 2)), np.array(d1, ndmin = 2))

        self.theta1G = (1/m) * g1
        self.theta2G = (1/m) * g2
        self.theta3G = (1/m) * g3


    def gradDescent(self):

        params = np.array(self.params)
        theta1 = params(0:3925)
        theta1 = np.resize(theta1, (785, 5))
        theta2 = params(3925:3955)
        theta2 = np.resize(theta2, (6, 5))
        theta3 = params(3955:4015)
        theta3 = np.resize(theta3, (6, 10))

        for i in range(self.steps):
            J = self.error(theta1, theta2, theta3, self.trainX, self.trainY)
            print("Iteration: ", i+1, " | error: ", J)
            self.fbProp(theta1, theta2, theta3)
            theta1 = theta1 - (self.alpha * self.theta1G)
            theta2 = theta2 - (self.alpha * self.theta2G)
            theta3 = theta3 - (self.alpha * self.theta3G)



        #On test set
        correct = self.test(theta1, theta2, theta3)
        print(correct/100, "%")


    def error(self, params, X, y):
        theta1 = params(0:3925)
        theta1 = np.resize(theta1, (785, 5))
        theta2 = params(3925:3955)
        theta2 = np.resize(theta2, (6, 5))
        theta3 = params(3955:4015)
        theta3 = np.resize(theta3, (6, 10))


        bias = np.ones((np.shape(y)(0), 1))
        a1 = self.sig(np.dot(X, theta1))
        a1 = np.hstack((bias, a1))
        a2 = self.sig(np.dot(a1, theta2))
        a2 = np.hstack((bias, a2))
        hyp = self.sig(np.dot(a2, theta3))

        #10 classes
        pt1 = ((-np.log(hyp) * y) - (np.log(1-hyp) * (1-y))).sum()
        J = 1/(40000) * pt1.sum()

        return J


    def error(self, theta1, theta2, theta3, X, y):
        bias = np.ones((np.shape(y)(0), 1))
        a1 = self.sig(np.dot(X, theta1))
        a1 = np.hstack((bias, a1))
        a2 = self.sig(np.dot(a1, theta2))
        a2 = np.hstack((bias, a2))
        hyp = self.sig(np.dot(a2, theta3))
        print(hyp(0, :))

        #10 classes
        pt1 = ((np.log(hyp) * y) + (np.log(1-hyp) * (1-y))).sum()
        J = - (1/(40000)) * pt1.sum()

        return J



    #def validate(self):

    def test(self, theta1, theta2, theta3):
        X = self.testX
        y = self.oneHot_T
        bias = np.ones((np.shape(y)(0), 1))
        a1 = self.sig(np.dot(X, (theta1)))
        a1 = np.hstack((bias, a1))
        a2 = self.sig(np.dot(a1, (theta2)))
        a2 = np.hstack((bias, a2))
        hyp = self.sig(np.dot(a2, (theta3)))

        correct = 0
        ans = np.array((0, 1, 2, 3, 4, 5, 6, 7, 8, 9))

        for i in range(np.shape(y)(0)):
            #fix backprop and forward prop then this
            guess = np.argmax(hyp(i, :))
            match = np.argmax(y(i, :))
            print("guess: ", guess, "| ans: ", match)
            if guess == match:
                correct = correct + 1;

        return correct



    def gradientCheck(self):
        params = np.array(self.params)
        theta1 = params(0:3925)
        theta1 = np.resize(theta1, (785, 5))
        theta2 = params(3925:3955)
        theta2 = np.resize(theta2, (6, 5))
        theta3 = params(3955:4015)
        theta3 = np.resize(theta3, (6, 10))
        self.fbProp(theta1, theta2, theta3)

        grad = self.theta1G.ravel()
        grad = np.append(grad, self.theta2G.ravel())
        grad = np.append(grad, self.theta3G.ravel())


        print("got grads")
        epsilon = 0.00001

        params2 = np.array(self.params)
        check = np.zeros(np.shape(params))
        for i in range(3965, np.size(params)):
            temp = params(i)
            params(i) = params(i) + epsilon
            params2(i) = params2(i) - epsilon
            check(i) = (self.error(params, self.trainX, self.trainY) - self.error(params2, self.trainX, self.trainY)) / (2 * epsilon)
            params(i) = temp
            params2(i) = temp
            print(grad(i), " ", check(i))



    def sigG(self, z):
        return (self.sig(z) * (1-self.sig(z)))


    def sig(self, z):
        return 1/(1+(np.exp(-z)))


    def printPictures(self):
        #number of training examples to iterate over

        for i in range(3):
            img = self.trainX(i, 1:).reshape((28,28))
            mb.title('Digit = {}'.format(np.argmax(self.trainY(i,:))))
            mb.imshow(img, cmap = 'gray_r')
            mb.show()



    def __init__(self, steps, alpha, nodes, h_layers):
        self.steps = steps
        self.alpha = alpha
        self.nodes = nodes
        self.h_layers = h_layers



obj = MNIST(100, 0.1, 5, 1);
obj.processImg();
obj.setThetas();
obj.gradDescent()

#obj.gradientCheck()
#obj.printPictures()