Converting Dask Array to Numpy Array

Hi,

I am trying out the example in “Predict Local Properties” section of the webpage ([PyMKS (Dask) Introduction.

-------------Script---------------------------------------------------------

x_delta = generate_delta(n_phases=2, shape=(21,21))

y_delta = solve_fe(x_delta,
elastic_modulus=(100,150),
poissons_ratio=(0.3,0.3),
macro_strain=0.001)[‘strain’][…,0]


I am trying to view the “y_delta” array with the print statements.
I obtained the following descriptions of the array.

print(‘y_delta \n’,y_delta)
y_delta
dask.array<getitem, shape=(2, 21, 21), dtype=float64, chunksize=(2, 21, 21), chunktype=numpy.ndarray>
print(‘da.array(y_delta) \n’,da.array(y_delta))
da.array(y_delta)
dask.array<getitem, shape=(2, 21, 21), dtype=float64, chunksize=(2, 21, 21), chunktype=numpy.ndarray>

Are there any way to print the numerical data rather than printing the description of the dask array?

For example, I was able to print the “X_delta” array with “numpy.array()” function, but I got error messages when I used the function, “numpy.array(y_delta)”.

print(‘np.arrary(x_delta) \n’,np.array(x_delta))
np.arrary(x_delta)
[[[0 0 0 … 0 0 0]
[0 0 0 … 0 0 0]
[0 0 0 … 0 0 0]

[0 0 0 … 0 0 0]
[0 0 0 … 0 0 0]
[0 0 0 … 0 0 0]]

[[1 1 1 … 1 1 1]
[1 1 1 … 1 1 1]
[1 1 1 … 1 1 1]

[1 1 1 … 1 1 1]
[1 1 1 … 1 1 1]
[1 1 1 … 1 1 1]]]

Thank you in advance
Woo-Jae

Hi @wooj, welcome here,

Dask Array are lazy, they are not computed until asked by the user. So a Dask Array is always a handle to something to compute in the future. You can preview it’s shape and how it chunked, but if you want the data, you need to ask.

In this small example, this won’t be a problem though, just get the Array (and convert it to a local Numpy array) with:

x_delta.compute()