class toarray(x, keepnone=False, **kwargs)[source]#

Small function to ensure consistent format for things that should be arrays (note: sc.toarray() and sc.promotetoarray() are identical).

Very similar to numpy.array(), with the main difference being that sc.toarray(3) will return np.array([3]) (i.e. a 1-d array that can be iterated over), while np.array(3) will return a 0-d array that can’t be iterated over.

  • x (any) – a number or list of numbers

  • keepnone (bool) – whether sc.toarray(None) should return np.array([]) or np.array([None], dtype=object)

  • kwargs (dict) – passed to numpy.array()


sc.toarray(5) # Returns np.array([5])
sc.toarray([3,5]) # Returns np.array([3,5])
sc.toarray(None, skipnone=True) # Returns np.array([])
New in version 1.1.0: replaced “skipnone” with “keepnone”; allowed passing kwargs to np.array().
New in version 2.0.1: added support for pandas Series and DataFrame