Dark matter in the universe evolves through gravity to form a complex network of halos, filaments, sheets and voids, that is known as the cosmic web. This complicated distribution of matter contains information about underlying laws of physics. Computational models of the physical processes of the matter distribution evolution, such as classical N-body simulations, are extremely resource intensive, as they track the action of gravity in an expanding universe using billions of particles as tracers of the cosmic matter distribution. We demonstrate the application of a machine learning technique called Generative Adversarial Networks (GAN) to learn models that can efficiently generate new, physically realistic realizations of the cosmic web. Generation of a new cosmic web realization with a GAN takes a fraction of a second, compared to the many hours needed by the N-body technique. In this talk I will also describe the application of Convolutional Neural Networks (CNN) to extract cosmological information from observed matter distributions. As CNNs can capture very complicated features in the data, they are able to extract more information than traditional methods, such as power spectra. In effect we can make more precise measurements of cosmological parameters from the same amount of data.