Variational hybrid quantum classical algorithms to optimizations are important applications for near-term quantum computing. This paper proposes two quantum algorithms (the second one is variational) for training neural networks. Both of them obtain exponential speedup at the number of samples and polynomial speedup at the dimension of the samples over classical training algorithms. Moreover, the proposed quantum algorithms return the classical information of the training weight so that the outputs can be used directly to solve other problems. For practicality, we draw the quantum circuits to implement the two algorithms. Finally, as an inspiration, we show how to apply the variational algorithm to achieve speedup at the number of constraints in solving convex optimization problems.