Two-dimensional materials could play an important role in beyond-CMOS (complementary metal–oxide–semiconductor) electronics, and the development of memristors for information storage and neuromorphic computing using such materials is of particular interest. However, the creation of high-density electronic circuits for complex applications is limited due to low device yield and high device-to-device variability. Here, we show that high-density memristive crossbar arrays can be fabricated using hexagonal boron nitride as the resistive switching material, and used to model an artificial neural network for image recognition. The multilayer hexagonal boron nitride is deposited using chemical vapour deposition, and the arrays exhibit a high yield (98%), low cycle-to-cycle variability (1.53%) and low device-to-device variability (5.74%). The devices exhibit different switching mechanisms depending on the electrode material used (gold for bipolar switching and silver for threshold switching), as well as characteristics (such as large dynamic range and zeptojoule-order switching energies) that make them suited for application in neuromorphic circuits.