Method for programming a Bayesian neural network comprising an input layer , an output layer and possibly one or more hidden layer(s) , each neuron of a layer (721-723) of the Bayesian neural network being fed with a plurality of synapses, wherein said plurality of synapses are implemented as a RRAM array of cells, each column of the RRAM array being associated with a synapse, each row of the array corresponding to a sample of the posterior probability of the synaptic coefficients after the neural network has been trained, each cell comprising at least a first resistor (511,512,513,611-1,612-1,613-1) in series with a first transistor (521,522,523, 621-1,622-1,623-1) the drains of the first transistors of the cells of a row being connected together with an input of a neuron , the gates of the first transistors of a row being connected together with a control line , the control lines of the N rows being connected to a control unit configured to switch in turn said control lines, the voltages output by all the neurons of a layer being simultaneously propagated to the next, or being output if the layer is the output layer , the successive voltages output by output layer providing a probability distribution ( p ( z )) of an inference from a vector of data when said vector of data is input to the input layer , said method comprising: (a) training a model of the Bayesian neural network on a training dataset, D , the posterior probability distribution of the synaptic coefficients p ( w | D ) of the network being sampled by a Markov Chain Monte Carlo (MCMC) algorithm, thereby providing a matrix W S of size S × Q, each row of said matrix corresponding to a sample of the synaptic coefficients and each column of said matrix corresponding to a synapse of said network; (b) decomposing the marginal posterior probability distribution of each synaptic coefficient, w q into a plurality of K Gaussian components, the k th Gaussian component of synaptic component w q having a median value μ q,k ; (c) transforming each sample of a synaptic coefficient, w q , in matrix w S into a quantized value to obtain a programming matrix W̃ S , said quantized value being selected as the mean value of a Gaussian component obtained at step (b) which is closest to said sample of synaptic coefficient; and (d) programming the first resistors of each row, n, of the RRAM array, by injecting therein a current of intensity I SET n , q = w ̃ n , q α 1 / γ during a SET operation, where w̃ n,q is the element at row n and column q of programming matrix W S and α,γ are coefficients characteristic of the RRAM array. (a) training a model of the Bayesian neural network on a training dataset, D , the posterior probability distribution of the synaptic coefficients p ( w | D ) of the network being sampled by a Markov Chain Monte Carlo (MCMC) algorithm, thereby providing a matrix W S of size S × Q, each row of said matrix corresponding to a sample of the synaptic coefficients and each column of said matrix corresponding to a synapse of said network; (b) decomposing the marginal posterior probability distribution of each synaptic coefficient, w q into a plurality of K Gaussian components, the k th Gaussian component of synaptic component w q having a median value μ q,k ; (c) transforming each sample of a synaptic coefficient, w q , in matrix w S into a quantized value to obtain a programming matrix W̃ S , said quantized value being selected as the mean value of a Gaussian component obtained at step (b) which is closest to said sample of synaptic coefficient; and (d) programming the first resistors of each row, n, of the RRAM array, by injecting therein a current of intensity I SET n , q = w ̃ n , q α 1 / γ during a SET operation, where w̃ n,q is the element at row n and column q of programming matrix W S and α,γ are coefficients characteristic of the RRAM array. <EOS>