import numpy as np example_array = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) example_array example_array[1, 1] example_array[:, 0] example_array[1, :] example_array[1:3, 1:3] array1 = np.array([1, 1, 1, 2, 2, 2, 1]) array2 = np.array([1, 2, 3, 4, 5, 6, 7]) array2[array1==1] array3 = np.array(['a', 'a', 'a', 'b', 'b', 'b', 'b']) array2[(array1==1) & (array3=='a')] array1 = np.array([1, 1, 1, 2, 2, 2, 1]) array2 = np.array([1, 2, 3, 4, 5, 6, 7]) array1 * 2 + 1 array1 * array2 matrix1 = np.matrix([[1, 2, 3], [4, 5, 6]]) matrix2 = np.matrix([1, 2, 3]) matrix1 * matrix2.transpose() data = np.genfromtxt('./data/examp_data.txt', delimiter=',', skip_header=1) data np.savetxt('./data/examp_output.txt', data, delimiter=',') data = np.genfromtxt('./data/examp_data_species_mass.txt', dtype=None, names=True, delimiter=',') data def export_to_csv(data, filename): outputfile = open(filename, 'wb') datawriter = csv.writer(outputfile) datawriter.writerows(data) outputfile.close() data = np.genfromtxt('./data/examp_data_species_mass.txt', dtype=None, names=True, delimiter=',') print data data['species'] data['mass'][data['species'] == 'DM'] data['mass'][(data['species'] == 'DM') & (data['site'] == 1)] np.random.rand(3, 5) np.random.randn(4, 2) min = 10 max = 20 np.random.randint(min, max, [10, 2])