0

I'm trying to plot without using Numpy, but what can I write as an alternative to the following functions?

The alternatives I found to some functions gave different outputs.

vel = np.zeros([n, m, 2], dtype = float) -----> vel = [ [ [0.0  for i in range(2)] for j in range(m) ] for k in range(n) ] gives different output.

xlins = np.linspace(0, m-1, m) ------> xlins = [i for i in range(m)] did not run. 


psi = 2d array

def PlotData(psi, m, n, scale):
    psi = list(map(list, zip(*psi)))

    #psi = np.flip(psi, 0)
    psi = psi[::-1]
    vel = np.zeros([n, m, 2], dtype = float)
    #vel = [ [ [0.0  for i in range(2)] for j in range(m) ] for k in range(n)]
    #rgb = np.zeros([n, m, 3], dtype = int)
    rgb = [ [ [0  for i in range(3)] for j in range(m) ] for k in range(n) ]
.
.
.
.

    xlins = np.linspace(0, m-1, m)
    #xlins = [i for i in range(m)]
    ylins = np.linspace(0, n-1, n)
    #ylins = [float(i) for i in range(m)]
    plt.streamplot(xlins, ylins, vel[:,:,0], vel[:,:,1], color='k', density=1)

I want to obtain the same output without using Numpy.

glibdud
  • 7,550
  • 4
  • 27
  • 37
  • Umm, this sounds like an XY problem. Why do you need to do `numpy` things without `numpy`? – Daniel F Aug 01 '19 at 10:56
  • Because I'm doing a research on Numpy performance. – Ebru Diler Aug 01 '19 at 11:05
  • 1
    Hello and welcome to SO! I have tested your code for `vel` and the _shapes_ do match. What **discrepancies** have you found? Besides, when you say that `xlins = [i for i in range(m)] did not run.`, what kind of error does it prompt? Keep in mind that `range` only accepts integers, and returns a list of integers. – David Aug 01 '19 at 12:23
  • Hello, there are arrows inside the plot figure. Arrows appear when I use Numpy. But it doesn't show up when I'm not using numpy. AttributeError: 'list' object has no attribute 'ndim' I got the error. It should be about what you said. Thanks a lot but I still haven't found an alternative function. – Ebru Diler Aug 01 '19 at 12:48
  • And I tried this : def my_func(low,up,leng): list = [] step = (up - low) / float(leng) for i in range(leng): list.append(low) low = low + step return list – Ebru Diler Aug 01 '19 at 13:03
  • 1
    `plt.streamplot` makes me guess that you use `import matplotlib.pyplot as plt` earlier in the code. Notice that matplotlib has a dependency in numpy, so "without numpy" is not met by just not importing numpy in your own code. – Leporello Aug 01 '19 at 14:55

0 Answers0