1
import numpy as np
import itertools
a = np.array([[1, 1, 3, 0, 0, 3, 2], [1, 3, 0, 0, 0, 3, 2], [1, 1, 10, 0, 0, 1, 0]])
for row in a:
    sites = a.shape[0]
    species = a.shape[1]
    Chao = []
    sing = np.where(row == 1, 1, 0)
    doub = np.where(row == 2, 1, 0)
    spec = np.where(row > 0, 1, 0)
    F1 = (sum(sing))**2
    F2 = float((sum(doub)))*2
    Sobs = sum(spec)
    if F2 == 0:
        Ch = Sobs
    else:
        Ch = Sobs + (F1/F2)
    Chao.append(Ch)
    print Chao

when I print Chao, the product of this loop I currently have this:

[7][4.5][4]

However, I would like either an array or list that looks like this:

([7][4.5][4])

What functions in numpy or list will allow me to do this in python?

1 Answer 1

1

The logic are correct. The Chao list should to be initialized outside of the loop.

Sign up to request clarification or add additional context in comments.

Comments

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.