0

I am trying to display a 2D numpy array of floats but whenever I print, the array is only printed as whole numbers. Is there any way I can display the full float?

I know I can get rid of np.array but I want the array to be displayed vertically.

import numpy as np

MPass = 100
MPL = 25
ME = 120
Mwob = ME + MPL + MPass
rho = 1.225
g = 9.8
R = 0.3
pi = 3.14159
A = pi * R** 2
Aduct = 1.5 * A
Wwob = Mwob * g
Mb = 300
e = 400
Nfan = 12
w, h = 4, 101
X = np.array([[0 for x in range(w)] for y in range(h)])
x = 0

while Mb < 401:
    Wb = Mb * g
    Wt = Wb + Wwob
    Mt = Mb + Mwob
    Pav = e * Mb
    Pav_fan = Pav/Nfan
    vi = (Pav_fan/(2*rho*Aduct))**(1/3)
    Tmax_fan = 2 * rho * Aduct * vi**2
    Ttmax = Tmax_fan * Nfan
    Fnet = Ttmax - Wt
    X[x][0] = Mb
    X[x][1] = Fnet
    X[x][2] = Mt
    a = Fnet/Mt
    if a < 0:
        t = 0
    else:
        t = ((2*762)/a)**0.5
    X[x][3] = t
    x = x + 1
    Mb = Mb + 1

print(X)

  • 1
    Check the type of np array you have. It could be defined as containing ints – Tarik Sep 30 '21 at 01:56
  • By the way this is too much code. See [example] – user202729 Sep 30 '21 at 01:58
  • [python - I am try to assigne float numbers from tuple to numpy array - Stack Overflow](https://stackoverflow.com/questions/63300414/i-am-try-to-assigne-float-numbers-from-tuple-to-numpy-array) (although that old question is quite poorly worded and also not have a [example]) – user202729 Sep 30 '21 at 01:59
  • try `X=np.zeros((h, w))` Creating it with all `0` makes a `int` dtype array. You don't want that. Learn what the basic properties of a array mean, `shape` and `dtype` – hpaulj Sep 30 '21 at 02:02

2 Answers2

0

Change the

X = np.array([[0 for x in range(w)] for y in range(h)])

to

X = np.array([[0 for x in range(w)] for y in range(h)], dtype=float)

Hope this is helpful! :D

PumpkinQ
  • 81
  • 3
0

you can try just casting the float: print(np.array(X,dtype=float))