Skip to content

Instantly share code, notes, and snippets.

@KenoLeon
Last active August 10, 2020 20:44
Show Gist options
  • Select an option

  • Save KenoLeon/c49ad7b9dd3ff02f233cfe3b9427394c to your computer and use it in GitHub Desktop.

Select an option

Save KenoLeon/c49ad7b9dd3ff02f233cfe3b9427394c to your computer and use it in GitHub Desktop.
Create Simple Numpy Arrays
import numpy as np
# -------------- ||| --------------
array_of_zeroes = np.zeros(10)
# array of 10 zeroes
print(array_of_zeroes)
# >>> [0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
# -------------- ||| --------------
array_of_ones = np.ones(6)
# array of 6 ones
print(array_of_ones)
# >>> [1. 1. 1. 1. 1. 1.]
# -------------- ||| --------------
range_array = np.arange(8)
# numbers in a range 0-8
print(range_array)
# >>> [0 1 2 3 4 5 6 7]
# -------------- ||| --------------
random_array = np.random.rand(6)
# 6 random numbers
print(random_array)
# >>> [0.37529593 0.90511026 0.68951624 0.95149275 0.06823498 0.092339 ]
# -------------- ||| --------------
random_int_array = np.random.randint(1, 6, 8)
# 8 Random ints between 1 and 6 inclusive
print(random_int_array)
# >>> [2 4 5 4 3 3 4 1]
# -------------- ||| --------------
linear_spaced_array = np.linspace( 0, 40, 5 )
# 5 Evenly spaced numbers from 0 to 40
print(linear_spaced_array)
# >>> [ 0. 10. 20. 30. 40.]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment