Skip to content

tensor.from_function doesn't work with np.random.randn #380

Closed
@tgkolda

Description

@tgkolda

I will be submitting a fix as part of #374

import numpy as np
import pyttb as ttb
np.random.seed(0)
T = ttb.tensor.from_function(np.random.randn, (4, 3, 2))
print(T)

produces

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[2], line 3
      1 #%%
      2 np.random.seed(0)
----> 3 T = ttb.tensor.from_function(np.random.randn, (4, 3, 2))
      4 print(T)

File ~\Documents\GIT Repos\pyttb\pyttb\tensor.py:217, in tensor.from_function(cls, function_handle, shape)
    214 shape = parse_shape(shape)
    216 # Generate data
--> 217 data = function_handle(shape)
    219 # Create the tensor
    220 return cls(data, shape, copy=False)

File numpy\\random\\mtrand.pyx:1306, in numpy.random.mtrand.RandomState.randn()

File numpy\\random\\mtrand.pyx:1467, in numpy.random.mtrand.RandomState.standard_normal()

File _common.pyx:657, in numpy.random._common.cont()

TypeError: 'tuple' object cannot be interpreted as an integer

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions