Skip to content

Instantly share code, notes, and snippets.

@NISH1001
Created April 27, 2020 08:35
Show Gist options
  • Save NISH1001/7c201a1c6e7369af20532ccc1b9f2a0b to your computer and use it in GitHub Desktop.
Save NISH1001/7c201a1c6e7369af20532ccc1b9f2a0b to your computer and use it in GitHub Desktop.
generate random numbers where column sums upto something
#!/usr/bin/env python3
import numpy as np
def main():
ncols = 3
nrows = 100
arr = np.random.random((nrows, ncols))
arr = arr / arr.sum(axis=0, keepdims=1) * 100
print(arr.shape)
print(arr.sum(axis=0))
np.savetxt("rand.csv", arr, delimiter=",")
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment