Esempio n. 1
0
 def testZeros(self): # make new datasets with zeros
     print("test zeros")
     dds = np.zeros(3, dtype=np.float)
     if isjava:
         self.assertEquals(1, dds.dtype.elements)
     self.assertEquals(1, dds.ndim)
     self.assertEquals(3, dds.shape[0])
     self.assertEquals(0, dds[0])
     dds = np.zeros((2,3), dtype=np.float)
     if isjava:
         self.assertEquals(1, dds.dtype.elements)
     self.assertEquals(2, dds.ndim)
     self.assertEquals(2, dds.shape[0])
     self.assertEquals(3, dds.shape[1])
     self.assertEquals(0, dds[0,0])
     dds = np.zeros_like(dds)
     if isjava:
         self.assertEquals(1, dds.dtype.elements)
     self.assertEquals(2, dds.ndim)
     self.assertEquals(2, dds.shape[0])
     self.assertEquals(3, dds.shape[1])
     self.assertEquals(0, dds[0,0])
     dds = np.zeros(np.array([1,2]), dtype=np.float)
     self.assertEqual((1,2), dds.shape)
     self.assertEquals(0, dds[0,0])
     dds = np.zeros_like(np.array([1,2]), dtype=np.float)
     self.assertEquals((2,), dds.shape)
     self.assertEquals(0, dds[0])
    def testEmptyListInput(self):
        array_input = dnp.array([])
        list_input = []

        zeros_output = dnp.array([])

        zeros_like_array = dnp.zeros_like(list_input)
        zeros_like_list = dnp.zeros_like(list_input)

        self.assertEquals(zeros_like_array.shape, (0,))
        self.checkitems(zeros_like_array, zeros_output)

        self.assertEquals(zeros_like_list.shape, (0,))
        self.checkitems(zeros_like_list, zeros_output)
    def test2dInput(self):
        arr_input = dnp.array([[1, 2], [3, 4], [5, 6]])
        list_input = [[1, 2], [3, 4], [5, 6]]

        zeros_output = dnp.array([[0, 0], [0, 0], [0, 0]])

        zeros_like_arr = dnp.zeros_like(arr_input)
        zeros_like_list = dnp.zeros_like(list_input)

        self.assertEquals(zeros_like_arr.shape, (3,2))
        self.checkitems(zeros_like_arr, zeros_output)

        self.assertEquals(zeros_like_list.shape, (3,2))
        self.checkitems(zeros_like_list, zeros_output)
    def testInput(self):
        list_input = [1, 2, 3]
        tuple_input = (1, 2, 3)
        arr_input = dnp.array([1, 2, 3])

        zeros_output = dnp.array([0, 0, 0])

        zeros_like_list = dnp.zeros_like(list_input)
        zeros_like_tuple = dnp.zeros_like(tuple_input)
        zeros_like_arr = dnp.zeros_like(arr_input)

        self.assertEquals(zeros_like_list.shape, (3,))
        self.checkitems(zeros_like_list, zeros_output)

        self.assertEquals(zeros_like_tuple.shape, (3,))
        self.checkitems(zeros_like_tuple, zeros_output)

        self.assertEquals(zeros_like_arr.shape, (3,))
        self.checkitems(zeros_like_arr, zeros_output)
Esempio n. 5
0
 def makeplotdata(self):
     '''Make a list of datasets to plot
     '''
     pdata = self.makefuncdata()
     pdata.insert(0, self.data)
     offset = self.data.min() - ((self.data.max() - self.data.min()) / 5.0)
     edata = self.data - pdata[1] + offset
     edata.name = "Error value"
     odata = _dnp.zeros_like(edata)
     odata.fill(offset)
     odata.name = "Error offset"
     pdata.insert(2, odata)
     pdata.insert(2, edata)
     return pdata
Esempio n. 6
0
 def makeplotdata(self, all=True):
     '''Make a list of datasets to plot
     all   -- if True, then make datasets for all functions
     '''
     pdata = self.makefuncdata(all=all)
     pdata.insert(0, self.data)
     if all:
         offset = self.data.min() - ((self.data.max() - self.data.min()) / 5.0)
         edata = self.data - pdata[1] + offset
         edata.name = "Error value"
         odata = _dnp.zeros_like(edata)
         odata.fill(offset)
         odata.name = "Error offset"
         pdata.insert(2, odata)
         pdata.insert(2, edata)
     return pdata