0

I'm trying to write a function that will solve this question: What is the probability that the minimal die is 3 when 5 dice are cast?

I've run into this error AttributeError: 'int' object has no attribute 'min', and I can't figure out how to fix it. The code worked fine before I made it a function.

Here is my function:

import numpy as np

def minimal_throw(throws, rng, n_reps = 10 ** 5):
    results = rng.integers(low = 1, high = 6 + 1, size = (n_reps, throws))
    minimas = throws.min(axis = 1)
    uniques, counts  = np.unique(minimas, return_counts = True)
    return {"face" : uniques, "probability" : counts / n_reps}

rng = np.random.default_rng()

simulated_throws = minimal_throw(5, rng = rng)
faces = simulated_throws["face"]
probabilities = simulated_throws["probability"]
6
  • I expect it to take the minima of every row in the matrix Commented Sep 28, 2022 at 11:51
  • There is no matrix in that line. Commented Sep 28, 2022 at 11:51
  • throws is not a matrix. Commented Sep 28, 2022 at 11:57
  • oh ok, I thought it was, makes sense why I can't have an axis of 1 then Commented Sep 28, 2022 at 12:03
  • 1
    I think what you want is minimas=results.min(axis=1) not throws.min(...) Commented Sep 28, 2022 at 12:05

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.